This repository has been archived by the owner on Sep 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-data-resize-0.5.py
63 lines (41 loc) · 1.75 KB
/
prepare-data-resize-0.5.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
# code reference : https://medium.com/datadriveninvestor/using-the-super-resolution-convolutional-neural-network-for-image-restoration-ff1e8420d846
import sys
import os
import cv2
# prepare degraded image by introducing quality distortions via resizing
FACTOR = 2
def prepare_images(path, FACTOR):
# loop through the file in the directory
for file in os.listdir(path):
# open the file
img = cv2.imread(path + '/' + file)
# find old and new image dimension
h, w, _ = img.shape
new_height = h // FACTOR
new_width = w // FACTOR
# resize the image - down
img = cv2.resize(img, (new_width, new_height), interpolation = cv2.INTER_CUBIC)
# resize the image - up
img = cv2.resize(img, (w, h), interpolation = cv2.INTER_CUBIC)
# save the image
print("Saving {}".format(file))
cv2.imwrite("dataset/0.5-resize-enlarged/{}".format(file), img)
def resize_images(path, FACTOR):
# loop through the file in the directory
for file in os.listdir(path):
# open the file
img = cv2.imread(path + '/' + file)
# find old and new image dimension
h, w, _ = img.shape
new_height = h // FACTOR
new_width = w // FACTOR
# resize the image - down
img = cv2.resize(img, (new_width, new_height), interpolation = cv2.INTER_CUBIC)
# save the image
print("Saving {}".format(file))
cv2.imwrite("dataset/0.5-resize/{}".format(file), img)
if __name__ == "__main__":
prepare_images('dataset/original/', FACTOR)
print("Resize images to factor " + str(FACTOR) + " and enlarged Done!")
resize_images('dataset/original/', FACTOR)
print("Resize images to factor " + str(FACTOR) + ", Done!")