-
Notifications
You must be signed in to change notification settings - Fork 15
/
downsample.py
59 lines (43 loc) · 1.6 KB
/
downsample.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
'''
A python program to downsample images.
This saves the resized images with same name and extension as input image in the destination folder
'''
from __future__ import print_function, division, absolute_import
import numpy as np
import cv2
from skimage import io
from os import listdir
# ============================================================================
# Destination to save downsampled images
f_save = "C:/Users/SAI RAJ/Desktop/HPC/floyd/super_resolution/data/ink2"
# Destination of input files
f_inp = "C:/Users/SAI RAJ/Desktop/HPC/floyd/super_resolution/data/ink"
# scaling factor for image in x and y direction, assign to "None",
# if you want to scale images by exact sizes
fx = 0.5
fy = 0.5
# the size of the image in x direction and y direction, used only if fx and fy are None.
x = None
y = None
# =============================================================================
arr = listdir(f_inp)
def load_data():
temp_y = io.imread_collection(f_inp + "*.png")
y = np.array([images for i, images in enumerate(temp_y)])
print("Loaded High Resolution images")
return y
def downsample(data):
for i in range(data.shape[0]):
img = data[i]
if fx is None:
small = cv2.resize(img, (x, y))
else:
small = cv2.resize(img, (0, 0), fx=0.5, fy=0.5)
small = cv2.cvtColor(small, cv2.COLOR_RGB2BGR)
name = arr[i]
path = f_save + "/" + name
cv2.imwrite(path, small)
if __name__ == "__main__":
data = load_data()
downsample(data)
print("Resizing done")