-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathefficiency.py
63 lines (56 loc) · 1.6 KB
/
efficiency.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
from skimage.measure import compare_ssim
import numpy as np
import cv2
import math
def psnr(img1 , img2):
mse = np.mean((img1 - img2) ** 2)
if mse == 0:
return 100
PIXEL_MAX = 255.0
PSNR = 20 * math.log10(PIXEL_MAX / math.sqrt(mse))
return PSNR
def ssim(img1 , img2):
(score, diff) = compare_ssim(img1, img2, full=True, multichannel=True)
diff = (diff * 255).astype("uint8")
return score
def meanIt(x):
y = 0
z = 0
a,b,c = x.shape
for i in range(a):
for j in range(b):
for k in range(c):
y = y+x[i][j][k]
z = z + 1
return y/z
def callIt(x,mean_x,y,mean_y):
z = 0
a,b,c = x.shape
for i in range(a):
for j in range(b):
for k in range(c):
z = z + (x[i][j][k]-mean_x)*(y[i][j][k]-mean_y)
return z
def correlationCoefficient(x,y):
mean_x, mean_y = meanIt(x), meanIt(y)
cov = callIt(x,mean_x,y,mean_y)
var_x = callIt(x,mean_x,x,mean_x)
var_y = callIt(y,mean_y,y,mean_y)
# print(sum(cov))
# print( math.sqrt(var_x))
#print(math.sqrt(var_y))
#return 2
return (cov / math.sqrt(var_x)) / math.sqrt(var_y)
def epi(x1,y1):
num = 0
den = 0
x = cv2.cvtColor(x1,cv2.COLOR_BGR2GRAY)
y = cv2.cvtColor(y1,cv2.COLOR_BGR2GRAY)
row,col = x.shape
# row,col,ch = img.shape
for i in range(row):
for j in range(col-1):
num = num + np.abs(y[i][j+1]-y[i][j])
den = den + np.abs(x[i][j+1] - x[i][j])
z = num/den
return z