-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_train_images.py
executable file
·48 lines (38 loc) · 1.33 KB
/
generate_train_images.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
#!/usr/bin/env python
import cv2
import numpy as np
from glob import glob
image_origin_dir = './images/origin'
image_resized_dir = './images/resized'
image_mono_dir = './images/mono'
image_train_dir = './images/pix2pix_format'
def _resize(filename) -> None:
origin = cv2.imread('%s/%s' % (image_origin_dir, filename,))
resized = cv2.resize(origin, None, fx=0.2, fy=0.2)
cv2.imwrite('%s/%s' % (image_resized_dir, filename,), resized)
def _merge_image(filename) -> None:
"""
A is Grayscale
B is Colorful
+---+ +---+ +------+
| A | + | B | -> | A B |
+---+ +---+ +------+
"""
origin = cv2.imread('%s/%s' % (image_resized_dir, filename,))
mono = cv2.imread('%s/%s' % (image_mono_dir, filename,))
new_canvas = cv2.hconcat([mono, origin])
cv2.imwrite('%s/%s' % (image_train_dir, filename,), new_canvas)
def main():
files = glob('%s/*.jpg' % (image_origin_dir,))
for image_path in files:
# origin to resized
_resize(image_path)
filename = image_path.split('/')[-1]
# Create Grayscale Image
img = cv2.imread('%s/%s' % (image_resized_dir, filename,))
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imwrite('%s/%s' % (image_mono_dir, filename,), gray)
#
_merge_image(filename)
if __name__ == "__main__":
main()