-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathevalUnwarp.m
102 lines (82 loc) · 2.74 KB
/
evalUnwarp.m
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function [ms, ld, li_d, wv, wh] = evalUnwarp(A, ref, data)
%EVALUNWARP compute MSSSIM and LD between the unwarped image and the scan
% A: unwarped image
% ref: reference image, the scan image
% ms: returned MS-SSIM value
% ld: returned local distortion value
% Matlab image processing toolbox is necessary to compute ssim. The weights
% for multi-scale ssim is directly adopted from:
%
% Wang, Zhou, Eero P. Simoncelli, and Alan C. Bovik. "Multiscale structural
% similarity for image quality assessment." In Signals, Systems and Computers,
% 2004. Conference Record of the Thirty-Seventh Asilomar Conference on, 2003.
%
% Local distortion relies on the paper:
% Liu, Ce, Jenny Yuen, and Antonio Torralba. "Sift flow: Dense correspondence
% across scenes and its applications." In PAMI, 2010.
%
% and its implementation:
% https://people.csail.mit.edu/celiu/SIFTflow/
x = A;
y = ref;
im1=imresize(imfilter(y,fspecial('gaussian',7,1.),'same','replicate'),0.5,'bicubic');
im2=imresize(imfilter(x,fspecial('gaussian',7,1.),'same','replicate'),0.5,'bicubic');
im1=im2double(im1);
im2=im2double(im2);
cellsize=3;
gridspacing=1;
sift1 = mexDenseSIFT(im1,cellsize,gridspacing);
sift2 = mexDenseSIFT(im2,cellsize,gridspacing);
SIFTflowpara.alpha=2*255;
SIFTflowpara.d=40*255;
SIFTflowpara.gamma=0.005*255;
SIFTflowpara.nlevels=4;
SIFTflowpara.wsize=2;
SIFTflowpara.topwsize=10;
SIFTflowpara.nTopIterations = 60;
SIFTflowpara.nIterations= 30;
[vx,vy,~]=SIFTflowc2f(sift1,sift2,SIFTflowpara);
rows1p = size(im1,1);
cols1p = size(im1,2);
% Li-D
rowstd_sum = 0;
for i = 1:rows1p
rowstd = std(vy(i, :),1);
rowstd_sum = rowstd_sum + rowstd;
end
rowstd_mean = rowstd_sum / rows1p;
colstd_sum = 0;
for i = 1:cols1p
colstd = std(vx(:, i),1);
colstd_sum = colstd_sum + colstd;
end
colstd_mean = colstd_sum / cols1p;
li_d = (rowstd_mean + colstd_mean) / 2;
% LD
d = sqrt(vx.^2 + vy.^2);
ld = mean(d(:));
% MS-SSIM
wt = [0.0448 0.2856 0.3001 0.2363 0.1333];
ss = zeros(5, 1);
for s = 1 : 5
ss(s) = ssim(x, y);
x = impyramid(x, 'reduce');
y = impyramid(y, 'reduce');
end
ms = wt * ss;
% wv and wh
rowstd_sum = 0;
for i = 1:size(data, 1)
rowstd_top = std(vy(data(i,2), data(i,1):data(i,3)),1) / (data(i,3)-data(i,1));
rowstd_bot = std(vy(data(i,4), data(i,1):data(i,3)),1) / (data(i,3)-data(i,1));
rowstd_sum = rowstd_sum + rowstd_top + rowstd_bot;
end
wv = rowstd_sum / (2 * size(data, 1));
colstd_sum = 0;
for i = 1:size(data, 1)
colstd_left = std(vx(data(i,2):data(i,4), data(i,1)),1) / (data(i,4)- data(i,2));
colstd_right = std(vx(data(i,2):data(i,4), data(i,3)),1) / (data(i,4)- data(i,2));
colstd_sum = colstd_sum + colstd_left + colstd_right;
end
wh = colstd_sum / (2 * size(data, 1));
end