-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreshape.py
34 lines (34 loc) · 1.08 KB
/
reshape.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
import PIL
import os
dirname = "Warwick QU Dataset (Released 2016_07_08)/"
reshapedirname = "reshaped_warwick/"
final_height = 400
final_width = 600
try:
os.stat(reshapedirname)
except:
os.mkdir(reshapedirname)
for subdirname in ["segments_train","segments_test","segments_train_eval","images_train","images_test","images_train_eval"]:
try:
os.stat(reshapedirname+subdirname)
except:
os.mkdir(reshapedirname+subdirname)
prefix_name = ["images","segments"]
suffix_name = ["train","test"]
for file in os.listdir(dirname):
if file.endswith(".bmp"):
img = Image.open(dirname+file)
width, height = img.size
istest,isanno = False,False
if file[:4] == "test":
istest = True
if file.find("anno") != -1:
isanno = True
if isanno:
# change the image to saturated
img = img.point(lambda i: i * 255)
reshaped_image = img = img.resize((final_width, final_height), PIL.Image.ANTIALIAS)
newfilename = reshapedirname+prefix_name[isanno]+"_"+suffix_name[istest]+"/"+file.split('.')[0]
newfilenamefull = newfilename+".png"
reshaped_image.save(newfilenamefull,"PNG")