-
Notifications
You must be signed in to change notification settings - Fork 0
/
resize_to_square.py
57 lines (43 loc) · 1.81 KB
/
resize_to_square.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from PIL import Image, ImageOps
from resizeimage import resizeimage
import os
imagepath='/home/scopeserver/RaidDisk/DeepLearning/mwang/progressive_growing_of_gans/dresses/'
#longersize=256
'''
for imagefile in sorted(os.listdir(imagepath)):
print imagefile
fullname = os.path.join(imagepath,imagefile)
img = Image.open(fullname)
longersize=max(img.size)
background = Image.new('RGB', (longersize, longersize), 'white')
background.paste(img, (int((longersize-img.size[0])/2), int((longersize-img.size[1])/2)))
img = background
img.save(fullname,'JPEG')
'''
'''
with open('/home/scopeserver/RaidDisk/DeepLearning/mwang/tensorflow/tensorflow/models/image/imagenet/107_classes_image_list.txt','r') as reader:
filelist = [line.rstrip() for line in reader]
for fullname in filelist:
print fullname
#fullname = os.path.join(imagepath,imagefile)
img = Image.open(fullname)
longersize=max(img.size)
background = Image.new('RGB', (longersize, longersize), 'white')
background.paste(img, (int((longersize-img.size[0])/2), int((longersize-img.size[1])/2)))
img = background
img.save(fullname,'JPEG', )
'''
for imagefile in sorted(os.listdir(imagepath)):
print imagefile
fullname = os.path.join(imagepath,imagefile)
img = Image.open(fullname)
longersize=max(img.size)
background = Image.new('RGB', (longersize, longersize), 'white')
background.paste(img, (int((longersize-img.size[0])/2), int((longersize-img.size[1])/2)))
img = background
img = img.resize((256,256),Image.BICUBIC)
#longersize=max(img.size)
#background = Image.new('RGB', (longersize, longersize), 'white')
#background.paste(img, (int((longersize-img.size[0])/2), int((longersize-img.size[1])/2)))
#img = background
img.save(fullname,'JPEG')