-
Notifications
You must be signed in to change notification settings - Fork 0
/
reduceImageSize.py
102 lines (85 loc) · 2.85 KB
/
reduceImageSize.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from skimage.transform import resize
from skimage.io import imread, imsave
from skimage.util import img_as_ubyte
import pandas as pd
import math
import os
parisOutPath = "resized_paris/"
chenOutPath = "resized_chen/"
shanghaiOutPath = 'resized_shanghai/'
try:
os.makedirs(parisOutPath)
os.makedirs(chenOutPath)
os.makedirs(shanghaiOutPath)
except:
print("folders created already")
chenList = pd.read_pickle('chenimageNameLs.pkl')
parisList = pd.read_pickle('parisimageNameLs.pkl')
shanghaiList = pd.read_pickle('shanghaiimageNameLs.pkl')
targetLongestEdge = 340
# for i in chenList:
# image = imread(i)
# print(type(image[0][0][0]))
# print(image.shape)
# height = image.shape[0]
# width = image.shape[1]
# if (height > width):
# width = math.ceil(width/height * targetLongestEdge)
# height = targetLongestEdge
# else:
# height = math.ceil(height/width * targetLongestEdge)
# width = targetLongestEdge
# image_resized = img_as_ubyte(resize(image, (height, width),anti_aliasing=True))
# print(image_resized.shape)
# import re
# search = re.search("(?<=/)(.*)$",i)
# filename = search.group()
# filename = chenOutPath+filename
# print(filename)
# imsave(filename,image_resized)
for i in parisList:
try:
image = imread(i)
except:
continue
print(type(image[0][0][0]))
print(image.shape)
height = image.shape[0]
width = image.shape[1]
if (height > width):
width = math.ceil(width/height * targetLongestEdge)
height = targetLongestEdge
else:
height = math.ceil(height/width * targetLongestEdge)
width = targetLongestEdge
image_resized = img_as_ubyte(resize(image, (height, width),anti_aliasing=True))
print(image_resized.shape)
import re
search = re.search("(?<=/)(.*)$",i)
filename = search.group()
filename = parisOutPath+filename
print(filename)
imsave(filename,image_resized)
# for i in shanghaiList:
# image = imread(i)
# print(type(image[0][0][0]))
# print(image.shape)
# height = image.shape[0]
# width = image.shape[1]
# if height >= targetLongestEdge or width >= targetLongestEdge:
# if (height > width):
# width = math.ceil(width/height * targetLongestEdge)
# height = targetLongestEdge
# else:
# height = math.ceil(height/width * targetLongestEdge)
# width = targetLongestEdge
# image_resized = img_as_ubyte(resize(image, (height, width),anti_aliasing=True))
# print(image_resized.shape)
# else:
# image_resized = image
# import re
# search = re.search("(?<=/)(.*)$",i)
# filename = search.group()
# filename = shanghaiOutPath+filename
# print(filename)
# imsave(filename,image_resized)