-
Notifications
You must be signed in to change notification settings - Fork 0
/
AtlantaPreprocess.py
36 lines (27 loc) · 979 Bytes
/
AtlantaPreprocess.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
from PIL import Image, ImageOps
import os
import cv2
def resize_to_square(path, new_size):
for name in os.listdir(path):
image = Image.open(path + name)
new_size = (new_size, new_size)
image = image.resize(new_size, Image.ANTIALIAS)
image.save(path + name)
def cut_to_many(path, to_cut):
name = path + os.listdir(path)[0]
image = cv2.imread(name)
image_count = 0
to_cut_limit = image.shape[0] // to_cut
print(image.shape)
for i in range(0, image.shape[0], to_cut_limit):
for j in range(0, image.shape[1], to_cut_limit):
new_image = image[i:i + to_cut_limit, j:j + to_cut_limit]
cv2.imwrite(path + str(image_count) + ".jpg", new_image)
image_count += 1
path = 'dataset/Atlanta/'
for name in os.listdir(path):
image = cv2.imread(path + name)
print(name, image.shape)
if len(os.listdir(path)) == 1:
resize_to_square(path, 1024 * 8)
cut_to_many(path, 8)