forked from ebranlard/matlab2python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSF.py
More file actions
56 lines (45 loc) · 1.37 KB
/
SF.py
File metadata and controls
56 lines (45 loc) · 1.37 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
# coding: UTF-8
import numpy as np
import cv2
import torch
import time
def SF_inside(img1 = None,img2 = None,fused = None):
fused = fused.float()
m,n = fused.shape
tmp1 = torch.zeros([m, n]).to(fused.device)
tmp2 = torch.zeros([m, n]).to(fused.device)
tmp1[:, 1:] = fused[:, :-1]
tmp1[:, 0] = fused[:, 0]
tmp2[1:, :] = fused[:-1, :]
tmp2[0, :] = fused[0, :]
RF = torch.sum((fused - tmp1) ** 2) / (m * n)
CF = torch.sum((fused - tmp2) ** 2) / (m * n)
# RF = 0
# CF = 0
# for fi in range(m):
# for fj in range(1,n):
# RF = RF + (fused[fi,fj] - fused[fi,fj - 1]) ** 2
#
# RF = RF / (m * n)
# for fj in range(n):
# for fi in range(1,m):
# CF = CF + (fused[fi,fj] - fused[fi - 1,fj]) ** 2
#
# CF = CF / (m * n)
output = torch.sqrt(RF + CF)
return output
def SF(img1=None, img2=None, fused=None):
# print(img1.shape)
# (512, 512, 3)
tmp = 0
for i in range(3):
tmp += SF_inside(img1[i, :, :], img2[i, :, :], fused[i, :, :])
return tmp / 3
if __name__ == '__main__':
img1 = torch.Tensor(cv2.imread('ue.png')).permute(2, 0, 1)
img2 = torch.Tensor(cv2.imread('oe.png')).permute(2, 0, 1)
fused = torch.Tensor(cv2.imread('fused.png')).permute(2, 0, 1)
s = time.time()
print(SF(img1, img2, fused))
d = time.time()
print(d-s)