-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_patch.py
30 lines (26 loc) · 943 Bytes
/
create_patch.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
import cv2
import numpy as np
import os
import random
if __name__ == '__main__':
dataset_path = "DataSets/DIV2K_train_HR"
output_path = "trainData/patches_40"
file_names = os.listdir(dataset_path)
img = []
total_num = 8000
patch_size = 40
step = 10
count = 0
for file_name in file_names:
current_img = cv2.imread(dataset_path + "/" + file_name, cv2.IMREAD_COLOR)
h0 = random.randint(0, 800)
w0 = random.randint(0, 800)
h, w, c = current_img.shape
m = 2
n = 5
for j in range(0, m):
for k in range(0, n):
temp = current_img[h0+j*step+j*patch_size:h0+j*step+j*patch_size+patch_size, w0+k*step+k*patch_size:w0+k*step+k*patch_size+patch_size, :]
count += 1
cv2.imwrite(output_path + "/" + f'{count}.png', temp)
print(f'{count}/{total_num}')