-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweightedTargetMatrix.py
More file actions
80 lines (49 loc) · 1.47 KB
/
Copy pathweightedTargetMatrix.py
File metadata and controls
80 lines (49 loc) · 1.47 KB
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
#!/usr/bin/env python
# coding: utf-8
# In[1]:
from PIL import Image
from IPython.display import display
import numpy as np
# In[2]:
img = Image.open("target.jpg")
dimension = 28
targetImgWidth = 1400
subimgWidth = targetImgWidth / dimension
print(subimgWidth)
# In[19]:
#display(img)
# In[25]:
outputMatrix = [[None]*dimension]*dimension
for x in range(dimension):
for y in range(dimension):
# for x in range(2):
# for y in range(2):
area = (x * subimgWidth, y *subimgWidth, (x + 1) * subimgWidth, (y + 1)* subimgWidth)
print(area)
cropped_img = img.crop(area)
# cropped_img.show()
display(cropped_img)
avgGrayVal = np.array(cropped_img).mean()
print(avgGrayVal)
outputMatrix[x][y] = avgGrayVal
print(outputMatrix)
# In[5]:
def getAvgValueMatrix():
outputMatrix = [[None]*dimension]*dimension
for x in range(dimension):
for y in range(dimension):
# for x in range(2):
# for y in range(2):
area = (x * subimgWidth, y *subimgWidth, (x + 1) * subimgWidth, (y + 1)* subimgWidth)
print(area)
cropped_img = img.crop(area)
# cropped_img.show()
display(cropped_img)
avgGrayVal = np.array(cropped_img).mean()
print(avgGrayVal)
outputMatrix[x][y] = avgGrayVal
print(outputMatrix)
return outputMatrix
# In[4]:
getAvgValueMatrix()
# In[ ]: