-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaskkit.py
73 lines (65 loc) · 2.24 KB
/
maskkit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import DataPrepKit.ApplyPixmapMask as mask
import argparse
from pathlib import Path
def main():
arper = argparse.ArgumentParser(
description="""
Apply a MASK image to every image file found all files
and/or directories of files listed as arguments.
""",
exit_on_error=False,
epilog="""
The MASK image format *must* be a 8-bit grayscale image. It
is assumed all images in the DIRECTORY is have the same
width/height dimensions.
""",
)
arper.add_argument(
'-Q', '--quiet',
dest="quiet",
action='store_true',
default=False,
help="""
Do *not* report to the CLI log which files are being read,
which are being written. Error messages are still
reported.
"""
)
arper.add_argument(
'-m', '--mask',
required=True,
dest='mask_image_file',
action='store',
type=Path,
help="""
The mask file. It is expected that the width/height of the
mask file must be exactly the same as the width/height for
every other input image, and for every input file in any
directory, which are specified as a command line
argument. The mask file *must* be formatted as an 8-bit
grayscale image. White pixels allow the associated pixel
in the input image to show in the output, black pixels set
the associated pixel in the output image to black pixels.
"""
)
arper.add_argument(
'input_images',
nargs='*',
action='store',
type=Path,
help="""
Path to image files, or directories containing image files,
which are the same size as the MASK image file
argument. Each file will be read as input, and a new masked
output file is created with the same filename, but the
string "masked_" prepended to the filename.
"""
)
(cli_config, remaining_argv) = arper.parse_known_args()
mask.applyAllFiles(
cli_config.input_images,
cli_config.mask_image_file,
verbose=(not cli_config.quiet),
)
if __name__ == "__main__":
main()