-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
36 lines (36 loc) · 1.21 KB
/
test.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
from skimage import data, io, filter
from skimage.transform import resize
from scipy.misc import imshow
from path import Path
import numpy as np
dir = Path("./great_depression/")
side = int(raw_input("Enter size: "))
values = {}
images = dir.files()
i = 0
or_pic = io.imread("MigrantMother.jpg", as_grey=True)
or_pic = np.divide(or_pic, 255.0)
length = or_pic.shape[0] - or_pic.shape[0] % side
width = or_pic.shape[1] - or_pic.shape[1] % side
matrix = np.zeros((length, width))
for image in images:
total = 0.0
pic = io.imread(image, as_grey=True)
if pic.max() > 1.0:
pic = np.divide(pic, 255.0)
size = min(pic.shape[0], pic.shape[1])
pic = pic[:size, :size]
pic = resize(pic, (side, side))
average = np.mean(pic)
values[image] = average, pic
for i in range(length / side):
for j in range(width / side):
least = 9999
im = or_pic[side * i: side * (i + 1), side * j: side * (j + 1)]
mean = np.mean(im)
for image in values:
if abs(mean - values[image][0]) < least:
best_pic, least = values[image][1], abs(mean - values[image][0])
print i, j
matrix[side * i: side * (i + 1), side * j: side * (j + 1)] = best_pic
imshow(matrix)