-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03.Transformation.py
102 lines (91 loc) · 2.52 KB
/
03.Transformation.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import argparse
import cv2
import sys
import os
from lib.transformation import Transformation
def transform(args) -> None:
transforms = []
for key, value in args._get_kwargs():
if value is True:
transforms.append(key)
root, dirs, files = next(os.walk(args.src_path))
dirname = os.path.dirname(args.src_path)
for file in files:
image_path = f"{dirname}/{file}"
image = cv2.imread(image_path)
image_dst_path = f"{args.dst_path}/{file}"
Transformer = Transformation(image)
Transformer.transform_one_image(image_dst_path, transforms)
def main(args) -> None:
try:
if (args.src_path):
if os.path.isdir(args.src_path):
if args.dst_path is not None and os.path.isdir(args.dst_path):
transform(args)
else:
msg = f"{sys.argv[0]} -src [SRC_PATH] -dst [DST_PATH]"
print(f"Usage: {msg}")
else:
image = cv2.imread(args.src_path)
Transformer = Transformation(image)
Transformer.plot_transformation_image()
else:
print(f"Usage: {sys.argv[0]} -src [SRC_PATH]")
except Exception as e:
print(e)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="A program to display image transformation."
)
parser.add_argument(
"-src",
"--src_path",
type=str,
required=True,
nargs="?",
help="Image file path."
)
parser.add_argument(
"-dst",
"--dst_path",
type=str,
nargs="?",
help="Destination directory path."
)
parser.add_argument(
"-gaussian",
"--gaussian_blur",
action="store_true",
help="Gaussian Transform"
)
parser.add_argument(
"-mask",
action="store_true",
help="Mask Transform"
)
parser.add_argument(
"-roi",
"--roi_objects",
action="store_true",
help="Roi Transform"
)
parser.add_argument(
"-analyze",
"--analyze_object",
action="store_true",
help="Analyze Transform"
)
parser.add_argument(
"-pseudo",
"--pseudolandmarks",
action="store_true",
help="Psudolandmark Transform"
)
parser.add_argument(
"-hist",
"--color_histogram",
action="store_true",
help="Color histogram Transform"
)
args = parser.parse_args()
main(args)