Skip to content

Commit f445025

Browse files
committed
[update] upload pypi and new CLI
1 parent da88508 commit f445025

20 files changed

+252
-704
lines changed

.editorconfig

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.py]
12+
charset = utf-8
13+
indent_style = space
14+
indent_size = 4
15+
end_of_line = lf
16+
insert_final_newline = true
17+
trim_trailing_whitespace = true
18+
19+
[*.{md,mdx}]
20+
trim_trailing_whitespace = false

.github/workflows/release.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Set up Python
13+
uses: actions/setup-python@v2
14+
with:
15+
python-version: "3.x"
16+
- name: Install dependencies
17+
run: |
18+
python -m pip install --upgrade pip
19+
pip install setuptools wheel twine
20+
- name: Build and publish
21+
env:
22+
TWINE_USERNAME: __token__
23+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
24+
run: |
25+
python setup.py sdist bdist_wheel
26+
twine upload --repository pypi dist/*

.github/workflows/test.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
branches:
10+
- main
11+
- master
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python: [3.7, 3.8, 3.9]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Setup Python
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: ${{ matrix.python }}
26+
- name: Install Tox and other packages
27+
run: pip install tox
28+
- name: Run Tox
29+
# Run tox using the version of Python in `PATH`
30+
run: tox -e py

.vscode/settings.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"python.testing.unittestEnabled": false,
3+
"python.testing.nosetestsEnabled": false,
4+
"python.testing.pytestEnabled": true,
5+
"python.envFile": "${workspaceRoot}/vscode.env"
6+
}

LICENSE

+21-674
Large diffs are not rendered by default.

MANIFEST.in

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include pyproject.toml
2+
include *.md
3+
include LICENSE
4+
recursive-include tests test*.py

README.md

+41-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
21
# Blur Generator
32

4-
Generate blur on image.
3+
This tool is for generating blur on images.
4+
5+
There are 3 types of blur modes of `motion`, `lens`, or `gaussian`.
6+
7+
We can use the results on model training or something else.
58

6-
There are 3 types of blur can be used with `motion`, `lens`, or `gaussian`.
9+
## Installation
710

8-
We can use the results on model training or something.
11+
```bash
12+
pip install blurgenerator
13+
```
914

1015
## Usage
1116

1217
```bash
13-
usage: main.py [-h] [--input INPUT] [--output OUTPUT] [--type TYPE] [--motion_blur_size MOTION_BLUR_SIZE]
14-
[--motion_blur_angle MOTION_BLUR_ANGLE] [--lens_radius LENS_RADIUS] [--lens_components LENS_COMPONENTS]
15-
[--lens_exposure_gamma LENS_EXPOSURE_GAMMA] [--gaussian_kernel GAUSSIAN_KERNEL]
18+
usage: blurgenerator [-h] [--input INPUT] [--output OUTPUT] [--type TYPE] [--motion_blur_size MOTION_BLUR_SIZE] [--motion_blur_angle MOTION_BLUR_ANGLE]
19+
[--lens_radius LENS_RADIUS] [--lens_components LENS_COMPONENTS] [--lens_exposure_gamma LENS_EXPOSURE_GAMMA]
20+
[--gaussian_kernel GAUSSIAN_KERNEL]
1621

1722
optional arguments:
1823
-h, --help show this help message and exit
@@ -33,27 +38,47 @@ optional arguments:
3338
Kernel for gaussian. Default is 100.
3439
```
3540

36-
## Results
41+
## Example and Result
3742

38-
* Original image
43+
- Original image
3944

4045
![original image](./doc/test.png)
4146

42-
* Motion blur
47+
- Motion blur
48+
49+
`blurgenerator --type motion --input ./doc/test.png --output ./doc/motion.png`
4350

44-
`python3 main.py --type motion --input ./doc/test.png --output ./doc/motion.png`
51+
```python
52+
import cv2
53+
from blurgenerator import motion_blur
54+
img = cv2.imread('test.png')
55+
result = motion_blur(img, size=100, angle=30)
56+
```
4557

4658
![motion blur image](./doc/motion.png)
4759

48-
* Lens blur
60+
- Lens blur
61+
62+
`blurgenerator--type lens --input ./doc/test.png --output ./doc/lens.png`
4963

50-
`python3 main.py --type lens --input ./doc/test.png --output ./doc/lens.png`
64+
```python
65+
import cv2
66+
from blurgenerator import lens_blur
67+
img = cv2.imread('test.png')
68+
result = lens_blur(img, radius=5, components=4, exposure_gamma=2)
69+
```
5170

5271
![lens blur image](./doc/lens.png)
5372

54-
* Gaussian blur
73+
- Gaussian blur
5574

56-
`python3 main.py --type gaussian --input ./doc/test.png --output ./doc/gaussian.png`
75+
`blurgenerator --type gaussian --input ./doc/test.png --output ./doc/gaussian.png`
5776

58-
![gaussian blur image](./doc/gaussian.png)
77+
```python
78+
import cv2
79+
from blurgenerator import gaussian_blur
80+
img = cv2.imread('test.png')
81+
result = gaussian_blur(img, 100)
82+
```
5983

84+
![gaussian blur image](./doc/gaussian.png)

pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools>=46.4.0", "wheel"]
3+
build-backend = "setuptools.build_meta"

requirements.txt

-3
This file was deleted.

setup.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[metadata]
2+
version = attr: blurgenerator.__version__
3+
license_files = LICENSE

setup.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import setuptools
2+
3+
with open('README.md', 'r', encoding='utf-8') as fh:
4+
long_description = fh.read()
5+
6+
setuptools.setup(
7+
name='BlurGenerator',
8+
author='Nat Lee',
9+
author_email='[email protected]',
10+
description='Fast generate blur image.',
11+
keywords='blur, generator, blur-image, cli',
12+
long_description=long_description,
13+
long_description_content_type='text/markdown',
14+
url='https://github.com/NatLee/Blur-Generator',
15+
project_urls={
16+
'Documentation': 'https://github.com/NatLee/Blur-Generator',
17+
'Bug Reports': 'https://github.com/NatLee/Blur-Generator/issues',
18+
'Source Code': 'https://github.com/NatLee/Blur-Generator',
19+
# 'Funding': '',
20+
# 'Say Thanks!': '',
21+
},
22+
package_dir={'': 'src'},
23+
packages=setuptools.find_packages(where='src'),
24+
classifiers=[
25+
# see https://pypi.org/classifiers/
26+
'Development Status :: 5 - Production/Stable',
27+
28+
'Intended Audience :: Developers',
29+
'Topic :: Software Development :: Build Tools',
30+
31+
'Programming Language :: Python :: 3',
32+
'Programming Language :: Python :: 3.7',
33+
'Programming Language :: Python :: 3.8',
34+
'Programming Language :: Python :: 3.9',
35+
'Programming Language :: Python :: 3 :: Only',
36+
'License :: OSI Approved :: MIT License',
37+
'Operating System :: OS Independent',
38+
],
39+
python_requires='>=3.7',
40+
install_requires=['opencv-python', 'scipy'],
41+
extras_require={
42+
'dev': ['check-manifest'],
43+
# 'test': ['coverage'],
44+
},
45+
entry_points={
46+
'console_scripts': [
47+
'blurgenerator=blurgenerator.cli:main'
48+
]
49+
}
50+
)
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""
22
Blur maker init
33
"""
4+
__version__ = "1.0.0"
45

56
from .motion_blur import motion_blur
67
from .lens_blur import lens_blur
78
from .gaussian_blur import gaussian_blur
9+
10+
from .cli import main

main.py src/blurgenerator/cli.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
"""
22
Blur Maker
3-
43
"""
54
import argparse
6-
75
from pathlib import Path
86

97
import cv2
108

11-
from blur_tools import motion_blur, lens_blur, gaussian_blur
12-
9+
from blurgenerator import motion_blur, lens_blur, gaussian_blur
1310

14-
if __name__ == "__main__":
11+
def main():
1512

1613
parser = argparse.ArgumentParser()
1714

@@ -40,23 +37,23 @@
4037
img = img / 255.
4138

4239
if args.type not in ['motion', 'lens', 'gaussian']:
43-
print('No type has been selected. Please specific `motion`, `lens`, or `gaussian`.')
40+
print('----- No type has been selected. Please specific `motion`, `lens`, or `gaussian`.')
4441
else:
4542
if args.type == 'motion':
4643
result = motion_blur(img, size=args.motion_blur_size, angle=args.motion_blur_angle)
4744

4845
elif args.type == 'lens':
49-
result = lens_blur(img, radius=5, components=4, exposure_gamma=2)
46+
result = lens_blur(img, radius=args.lens_radius, components=args.lens_components, exposure_gamma=args.lens_exposure_gamma)
5047

5148
elif args.type == 'gaussian':
52-
result = gaussian_blur(img, 100)
49+
result = gaussian_blur(img, args.gaussian_kernel)
5350

5451
cv2.imwrite(args.output, result*255)
5552

5653
else:
57-
print('Only support common types of image `.jpg` and `.png`.')
54+
print('----- Only support common types of image `.jpg` and `.png`.')
5855

5956
else:
60-
print('File not exists!')
57+
print('----- File not exists!')
6158
else:
62-
print('Please specific image for input.')
59+
print('----- Please specific image for input.')
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/__init__.py

Whitespace-only changes.

tests/test_blurgenerator.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import unittest
2+
import numpy as np
3+
from blurgenerator import motion_blur, lens_blur, gaussian_blur
4+
5+
class TestBlurGenerator(unittest.TestCase):
6+
7+
def test_motion_blur(self):
8+
rgb = np.random.randint(255, size=(50, 50, 3),dtype=np.uint8)
9+
blur_img = motion_blur(rgb)
10+
self.assertFalse(np.array_equal(rgb, blur_img))
11+
12+
def test_lens_blur(self):
13+
rgb = np.random.randint(255, size=(50, 50, 3),dtype=np.uint8)
14+
blur_img = lens_blur(rgb)
15+
self.assertFalse(np.array_equal(rgb, blur_img))
16+
17+
def test_gaussian_blur(self):
18+
rgb = np.random.randint(255, size=(50, 50, 3),dtype=np.uint8)
19+
blur_img = gaussian_blur(rgb, kernel=3)
20+
self.assertFalse(np.array_equal(rgb, blur_img))
21+
22+
if __name__ == '__main__':
23+
unittest.main()

tox.ini

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[tox]
2+
envlist = py{37,38,39}
3+
minversion = 3.3.0
4+
isolated_build = true
5+
6+
[testenv]
7+
deps =
8+
check-manifest >= 0.42
9+
pytest
10+
commands =
11+
check-manifest --ignore 'tox.ini,tests/**,.editorconfig,vscode.env,.vscode/**'
12+
python setup.py check -m -s
13+
pytest tests {posargs}

vscode.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PYTHONPATH=/;src/;${PYTHONPATH}

0 commit comments

Comments
 (0)