A configurable batch script for several simple image operations (crop, affine transformation, split, combination, comparison, etc.).
With this workflow script, image operations can be easily & automatically performed following the guidance of which has been configured in a *.yml file, an example is as below:
(op1: split images; op2: combine them back; op3: evaluate their similarity)
opencv-python
PyYAML
numpy
scikit-image (for evaluation metrics)
- Put your image files in a structure like this:
.
├── raw
│ ├── 1.png
│ ├── 2.png
│ ├── 3.png
│ ├── 4.png
│ └── ...
├── compare # only if comparison is needed
│ ├── 1.png
│ ├── 2.png
│ ├── 3.png
│ ├── 4.png
│ └── ...
└─── result-
Copy one of the configure templates in 'configs' directory (e.g.
configs/workflow.yml) toconfigs/my_workflow.yml(leaving the original as a backup). -
Modify
configs/my_workflow.ymlas you need. Beware thatinput,compare,outputfields should be set to corresponding directory paths.
input: 'raw'
compare: 'compare'
output: 'result'- Run
python workflow.py configs/my_workflow.yml
usage: workflow.py [-h] [--mode {default, 1_to_1, 1_to_n, n_to_1, 2_to_0, n_to_0}]
ymlpath
usage: python [filename].py configs/[config].yml
positional arguments:
ymlpath
optional arguments:
-h, --help show this help message and exit
--mode {default, 1_to_1, 1_to_n, n_to_1, 2_to_0, n_to_0}
set to `default` or `{x}_to_{y}`. x: num of images
handled once, y: if n, a folder will be created for
each input image. The following example shows the configure file to split images in folder val into 2 × 2 tiles (saved in split folder) and then combine them back (saved in combine folder). Afterwards, our op3 will check if the inputs and combined results are exactly the same. (by ssim)
workflow:
- op1:
__meta__:
input: 'val' # input directory
output: 'split'
recursively: False # recursively = False: not include sub directory
split:
tiles:
w: 2
h: 2
- op2:
__meta__:
input: 'split'
output: 'combine'
recursively: True # recursively = True: include sub directory
combine:
one_folder_in_axis: 'xy' # one folder in one output image
priority_axis: 'x' # row-major
tiles:
w: 2 # num_a_row
h: 2 # rows(folders)
- op3:
__meta__:
input: 'val'
compare: 'combine'
evaluate:
- f1
- f2
- ssimThe running result snapshot is shown in preceding What Can it Do part.
Also, a full-version configure template is available here.
