-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmath_calc.py
More file actions
52 lines (48 loc) · 1.35 KB
/
Copy pathmath_calc.py
File metadata and controls
52 lines (48 loc) · 1.35 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
import numpy as np
'''
@describe
img1 and img2 must be in the same shape
size(shape) should be 3
@param img1
@param img2
@return difference of img1 and img2, we don't use img1-img2 since
dtype of img1 and img2 are unit8, (1-2) will be 255
'''
def diff(img1, img2):
res = np.zeros((img1.shape),dtype=np.uint8)
for h in range(img1.shape[0]):
for w in range(img1.shape[1]):
for c in range(img1.shape[2]):
res[h][w][c] = max(img1[h][w][c],img2[h][w][c]) - min(img1[h][w][c],img2[h][w][c])
return res
'''
@describe
return count of same pixel in img1 and img2
img1 and img2 must be in same size
@param img1
@param img2
@return cnt
'''
def same_cnt(img1,img2):
cnt = 0
for h in range(img1.shape[0]):
for w in range(img1.shape[1]):
res = 0
for c in range(img1.shape[2]):
res += max(img1[h][w][c],img2[h][w][c]) - min(img1[h][w][c],img2[h][w][c])
if res < 10:
cnt += 1
print cnt
return cnt
'''
@param img
@return sum of every pixel in img, then average
'''
def average(img):
res = 0
for h in range(img.shape[0]):
for w in range(img.shape[1]):
res += sum(img[h][w])
res /= img.size * img.shape[2]
#print 'sum: ',res
return res