-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSSIM.m
More file actions
55 lines (31 loc) · 986 Bytes
/
SSIM.m
File metadata and controls
55 lines (31 loc) · 986 Bytes
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
function SSIM
img1 = double(imread('CIDIQ\Images\Original\final01.bmp'));
img2 = double(imread('CIDIQ\Images\Reproduction\1_JPEG2000_Compression\final01_d1_l1.bmp'));
[xMean,xVar] = meanAndVar(img1);
[yMean,yVar] = meanAndVar(img2);
total_pixels = size(img1,1)*size(img1,2);
total = double(zeros(1,3));
x = double(zeros(1,3));
y = double(zeros(1,3));
for i = 1:size(img1,1)
for j = 1:size(img1,2)
x(1,:) = img1(i,j,:);
y(1,:) = img2(i,j,:);
xx = x(1,:) - xMean;
yy = y(1,:) - yMean;
total(1,:) = total(1,:) + (xx.*yy);
end
end
cov = total(1,:) / total_pixels;
c1 = 255 * 0.01;
c2 = 255 * 0.03;
cov = sum(cov);
xMean = sum(xMean);
yMean = sum(xMean);
xVar = sum(xVar);
yVar = sum(yVar);
above = (2*xMean*yMean + c1)*(2*cov + c2);
below = (xMean^2 + yMean^2 + c1)*(xVar + yVar +c2);
ssim = above / below;
ssim
end