-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathmsssim.m
103 lines (83 loc) · 2.16 KB
/
msssim.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
103
function overall_mssim = msssim(img1, img2, K, win, level, weight, method)
% Multi-scale Structural Similarity Index (MS-SSIM)
% Z. Wang, E. P. Simoncelli and A. C. Bovik, "Multi-scale structural similarity
% for image quality assessment," Invited Paper, IEEE Asilomar Conference on
% Signals, Systems and Computers, Nov. 2003
if (nargin < 2 || nargin > 7)
overall_mssim = -Inf;
return;
end
if (~exist('K'))
K = [0.01 0.03];
end
if (~exist('win'))
win = fspecial('gaussian', 11, 1.5);
end
if (~exist('level'))
level = 5;
end
if (~exist('weight'))
weight = [0.0448 0.2856 0.3001 0.2363 0.1333];
end
if (~exist('method'))
method = 'product';
end
if (size(img1) ~= size(img2))
overall_mssim = -Inf;
return;
end
[M N] = size(img1);
if ((M < 11) || (N < 11))
overall_mssim = -Inf;
return
end
if (length(K) ~= 2)
overall_mssim = -Inf;
return;
end
if (K(1) < 0 || K(2) < 0)
overall_mssim = -Inf;
return;
end
[H W] = size(win);
if ((H*W)<4 || (H>M) || (W>N))
overall_mssim = -Inf;
return;
end
if (level < 1)
overall_mssim = -Inf;
return
end
min_img_width = min(M, N)/(2^(level-1));
max_win_width = max(H, W);
if (min_img_width < max_win_width)
overall_mssim = -Inf;
return;
end
if (length(weight) ~= level || sum(weight) == 0)
overall_mssim = -Inf;
return;
end
if (method ~= 'wtd_sum' & method ~= 'product')
overall_mssim = -Inf;
return;
end
downsample_filter = ones(2)./4;
im1 = double(img1);
im2 = double(img2);
for l = 1:level
[mssim_array(l) ssim_map_array{l} mcs_array(l) cs_map_array{l}] = ssim_index_new(im1, im2, K, win);
% [M N] = size(im1);
filtered_im1 = imfilter(im1, downsample_filter, 'symmetric', 'same');
filtered_im2 = imfilter(im2, downsample_filter, 'symmetric', 'same');
clear im1, im2;
im1 = filtered_im1(1:2:end, 1:2:end);
im2 = filtered_im2(1:2:end, 1:2:end);
end
if (method == 'product')
% overall_mssim = prod(mssim_array.^weight);
overall_mssim = prod(mcs_array(1:level-1).^weight(1:level-1))*(mssim_array(level).^weight(level));
else
weight = weight./sum(weight);
overall_mssim = sum(mcs_array(1:level-1).*weight(1:level-1)) + mssim_array(level).*weight(level);
end