diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-08-30 01:57:00 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-08-30 01:57:00 +0300 |
commit | 61f13a8708cfb0adadf31b3d1ffe5f70b1103e0f (patch) | |
tree | 5386c793836e85801fd2c9116b83b191247c63b5 | |
parent | factor common code out (diff) | |
download | filters-61f13a8708cfb0adadf31b3d1ffe5f70b1103e0f.tar.gz filters-61f13a8708cfb0adadf31b3d1ffe5f70b1103e0f.zip |
more useful help messages + README update
-rw-r--r-- | README.md | 52 | ||||
-rw-r--r-- | bin/box_blur.py | 12 | ||||
-rw-r--r-- | bin/gaussian_blur.py | 15 | ||||
-rw-r--r-- | bin/shift.py | 19 |
4 files changed, 68 insertions, 30 deletions
@@ -7,27 +7,59 @@ matrices. Prerequisites ------------- -Python 3.4 or higher is required. -Additionally, [OpenCV]'s Python bindings are used for image manipulation. -Please note that [NumPy] is also required as a transitive dependency. +* Python 3.4 or higher +* [numpy] +* [opencv-python] + The versions below have been verified to work properly. | Software | Version | | ------------- | ------- | -| Python | 3.5.1 | +| CPython | 3.5.1 | | numpy | 1.11.0 | | opencv-python | 3.1.0 | -[NumPy]: http://www.numpy.org/ -[OpenCV]: http://opencv.org/ +[numpy]: http://www.numpy.org/ +[opencv-python]: http://opencv.org/ + +Windows binaries for CPython can be acquired at +http://www.lfd.uci.edu/~gohlke/pythonlibs/. -Windows binaries of the required packages for CPython can be acquired at the -usual place: http://www.lfd.uci.edu/~gohlke/pythonlibs/. -Please note that OpenCV's Python bindings require [Visual C++ Redistributable -for Visual Studio 2015] to be installed on Windows. +OpenCV's Python bindings require [Visual C++ Redistributable for Visual Studio +2015] on Windows. [Visual C++ Redistributable for Visual Studio 2015]: https://www.microsoft.com/en-us/download/details.aspx?id=48145 +Usage +----- + +Run the scripts from the top-level directory using `python -m`. +Pass the `--help` flag to a script to examine its detailed usage information. + +For example (using Windows path format): + + > python -m bin.box_blur img\Lenna.png --radius 3 + +The complete list of usable scripts is given below. + +* box_blur.py — Apply box blur to an image. +* gaussian_blur.py — Apply Gaussian blur to an image. +* shift.py — Shift an image by a few pixels in a specified direction. + +Linting +------- + +Requires [PyLint]. +Run from the top-level directory: + + > pylint filters + ... + + > pylint bin + ... + +[PyLint]: https://www.pylint.org/ + License ------- diff --git a/bin/box_blur.py b/bin/box_blur.py index 9d5d1cd..d570f5a 100644 --- a/bin/box_blur.py +++ b/bin/box_blur.py @@ -22,13 +22,15 @@ def _main_box_blur(img_path, radius=DEFAULT_RADIUS, output_path=None): image.save(output_path, output) def _parse_args(args=sys.argv): - parser = argparse.ArgumentParser() - parser.add_argument('img_path') - parser.add_argument('--output', '-o', - dest='output_path', default=None) + parser = argparse.ArgumentParser( + description='Apply box blur to an image.') + parser.add_argument('img_path', help='source image file path') + parser.add_argument('--output', '-o', dest='output_path', default=None, + help='save new image to a file') parser.add_argument('--radius', '-r', type=cmd_line.parse_non_negative_integer, - default=DEFAULT_RADIUS) + default=DEFAULT_RADIUS, + help='specify convolution kernel radius') return parser.parse_args(args[1:]) def _main(args=sys.argv): diff --git a/bin/gaussian_blur.py b/bin/gaussian_blur.py index d530547..c2aa79a 100644 --- a/bin/gaussian_blur.py +++ b/bin/gaussian_blur.py @@ -26,15 +26,18 @@ def _main_gaussian_blur( image.save(output_path, output) def _parse_args(args=sys.argv): - parser = argparse.ArgumentParser() - parser.add_argument('img_path') - parser.add_argument('--output', '-o', - dest='output_path', default=None) + parser = argparse.ArgumentParser( + description='Apply Gaussian blur to an image.') + parser.add_argument('img_path', help='source image file path') + parser.add_argument('--output', '-o', dest='output_path', default=None, + help='save new image to a file') parser.add_argument('--sigma', '-s', - type=float, default=DEFAULT_SIGMA) + type=float, default=DEFAULT_SIGMA, + help='specify the sigma coefficient in the Gaussian formula') parser.add_argument('--radius', '-r', type=cmd_line.parse_non_negative_integer, - default=DEFAULT_RADIUS) + default=DEFAULT_RADIUS, + help='specify convolution kernel radius') return parser.parse_args(args[1:]) def _main(args=sys.argv): diff --git a/bin/shift.py b/bin/shift.py index 8dfd76a..94db333 100644 --- a/bin/shift.py +++ b/bin/shift.py @@ -32,17 +32,18 @@ def _parse_direction(s): raise argparse.ArgumentTypeError('invalid direction: ' + s) def _parse_args(args=sys.argv): - parser = argparse.ArgumentParser() - parser.add_argument('img_path') - parser.add_argument('--output', '-o', - dest='output_path', default=None) - parser.add_argument('--direction', '-d', - type=_parse_direction, - choices=Direction, - default=DEFAULT_DIRECTION) + parser = argparse.ArgumentParser( + description='Shift an image by a few pixels in a specified direction.') + parser.add_argument('img_path', help='source image file path') + parser.add_argument('--output', '-o', dest='output_path', default=None, + help='save new image to a file') + parser.add_argument('--direction', '-d', choices=Direction, + type=_parse_direction, default=DEFAULT_DIRECTION, + help='specify shifting direction') parser.add_argument('--distance', '-n', type=cmd_line.parse_non_negative_integer, - default=DEFAULT_DISTANCE) + default=DEFAULT_DISTANCE, + help='specify shift size (in pixels)') return parser.parse_args(args[1:]) def _main(args=sys.argv): |