-
Notifications
You must be signed in to change notification settings - Fork 34
/
Crop_DIV2K.py
38 lines (33 loc) · 1.52 KB
/
Crop_DIV2K.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
import os
import cv2
import glob
import numpy as np
cropSize = 256
num = 100
# Crop SIDD
# GT = glob.glob(os.path.join('/home/yang/Documents/Yang_Liu/Research_Projects/Data/SIDD/SIDD_Medium_Srgb/GT', '*.PNG'))
# Noisy = glob.glob(os.path.join('/home/yang/Documents/Yang_Liu/Research_Projects/Data/SIDD/SIDD_Medium_Srgb/Noisy', '*.PNG'))
GT = glob.glob(os.path.join('/home/zhenyue/Data/SIDD/SIDD_Medium_Srgb/GT', '*.PNG'))
Noisy = glob.glob(os.path.join('/home/zhenyue/Data/SIDD/SIDD_Medium_Srgb/Noisy', '*.PNG'))
GT.sort()
Noisy.sort()
# out_dir = '/home/yang/Documents/Yang_Liu/Research_Projects/Data/SIDD/SIDD_Medium_Srgb_Patches'
out_dir = '/home/zhenyue/Data/SIDD/SIDD_Medium_Srgb_Patches'
if not os.path.exists(out_dir):
os.mkdir(out_dir)
if not os.path.exists(os.path.join(out_dir, 'GT')):
os.mkdir(os.path.join(out_dir, 'GT'))
if not os.path.exists(os.path.join(out_dir, 'Noisy')):
os.mkdir(os.path.join(out_dir, 'Noisy'))
for i in range(len(GT)):
image = cv2.imread(GT[i])
noisy_image = cv2.imread(Noisy[i])
endw, endh = image.shape[0], image.shape[1]
assert (endw >= cropSize) and (endh >= cropSize)
for k in range(num):
x = np.random.randint(0, endw - cropSize)
y = np.random.randint(0, endh - cropSize)
crop = image[x:(cropSize + x), y:(cropSize + y), :]
noisy_crop = noisy_image[x:(cropSize + x), y:(cropSize + y), :]
cv2.imwrite(os.path.join(out_dir, 'GT', '%d_%d.PNG'%(i, k)), crop)
cv2.imwrite(os.path.join(out_dir, 'Noisy', '%d_%d.PNG' % (i, k)), noisy_crop)