-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_dataset.py
More file actions
39 lines (32 loc) · 1.16 KB
/
create_dataset.py
File metadata and controls
39 lines (32 loc) · 1.16 KB
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
from PIL import Image
import os
import os.path
IMAGE_DIR = 'SR_training_datasets/T91'
SAVE_DIR = 'dataset'
IMG_SIZE = 127
LOW_RES = 63
images = os.listdir(IMAGE_DIR)
counter = 1
for image in images:
img_path = os.path.join(IMAGE_DIR, image)
img = Image.open(img_path)
width, height = img.size
for i in range(0, width-IMG_SIZE, 50):
for j in range(0, height-IMG_SIZE, 50):
ref_img = img.crop((i, j,
i + IMG_SIZE, j + IMG_SIZE))
resized_img = ref_img.resize(
(LOW_RES, LOW_RES))
bicubic_img = resized_img.resize(
(IMG_SIZE, IMG_SIZE), Image.BICUBIC)
crop_name = image.split('.')[:-1]
crop_name.append(str(i))
crop_name.append(str(j))
crop_name.append('.jpg')
crop_name = ''.join(crop_name)
bicubic_path = os.path.join(SAVE_DIR, 'bicubic', crop_name)
ref_path = os.path.join(SAVE_DIR, 'reference', crop_name)
ref_img.save(ref_path)
bicubic_img.save(bicubic_path)
print('[%i] Croped image: %s' % (counter, image))
counter = counter + 1