-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimageQualityIndex.m
103 lines (94 loc) · 3.34 KB
/
imageQualityIndex.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 [quality, quality_map] = imageQualityIndex (img1, img2, block_size)
%========================================================================
% * Note: img_qi is renamed as imageQualityIndex
%
%Copyright (c) 2001 The University of Texas at Austin
%All Rights Reserved.
%
%Author : Zhou Wang
%Version : 1.0
%
%The authors are with the Laboratory for Image and Video Engineering
%(LIVE), Department of Electrical and Computer Engineering, The
%University of Texas at Austin, Austin, TX.
%
%Kindly report any suggestions or corrections to [email protected]
%
%Acknowledgement:
%The author would like to thank Mr. Umesh Rajashekar, the Matlab master
%in our lab, for spending his precious time and giving his kind help
%on writing this program. Without his help, this program would not
%achieve its current efficiency.
%
%========================================================================
%
%This is an efficient implementation of the algorithm for calculating
%the universal image quality index proposed by Zhou Wang and Alan C.
%Bovik. Please refer to the paper "A Universal Image Quality Index"
%by Zhou Wang and Alan C. Bovik, published in IEEE Signal Processing
%Letters, 2001. In order to run this function, you must have Matlab's
%Image Processing Toobox.
%
%Input : an original image and a test image of the same size
%Output: (1) an overall quality index of the test image, with a value
% range of [-1, 1].
% (2) a quality map of the test image. The map has a smaller
% size than the input images. The actual size is
% img_size - BLOCK_SIZE + 1.
%
%Usage:
%
%1. Load the original and the test images into two matrices
% (say img1 and img2)
%
%2. Run this function in one of the two ways:
%
% % Choice 1 (suggested):
% [qi qi_map] = img_qi(img1, img2);
%
% % Choice 2:
% [qi qi_map] = img_qi(img1, img2, BLOCK_SIZE);
%
% The default BLOCK_SIZE is 8 (Choice 1). Otherwise, you can specify
% it by yourself (Choice 2).
%
%3. See the results:
%
% qi %Gives the over quality index.
% imshow((qi_map+1)/2) %Shows the quality map as an image.
%
%========================================================================
if (nargin == 1 | nargin > 3)
quality = -Inf;
quality_map = -1*ones(size(img1));
return;
end
if (size(img1) ~= size(img2))
quality = -Inf;
quality_map = -1*ones(size(img1));
return;
end
if (nargin == 2) % sliding window, B by B
block_size = 8;
end
N = block_size.^2;
sum2_filter = ones(block_size);
img1_sq = img1.*img1;
img2_sq = img2.*img2;
img12 = img1.*img2;
img1_sum = filter2(sum2_filter, img1, 'valid');
img2_sum = filter2(sum2_filter, img2, 'valid');
img1_sq_sum = filter2(sum2_filter, img1_sq, 'valid');
img2_sq_sum = filter2(sum2_filter, img2_sq, 'valid');
img12_sum = filter2(sum2_filter, img12, 'valid');
img12_sum_mul = img1_sum.*img2_sum;
img12_sq_sum_mul = img1_sum.*img1_sum + img2_sum.*img2_sum;
numerator = 4*(N*img12_sum - img12_sum_mul).*img12_sum_mul;
denominator1 = N*(img1_sq_sum + img2_sq_sum) - img12_sq_sum_mul;
denominator = denominator1.*img12_sq_sum_mul;
quality_map = ones(size(denominator));
index = (denominator1 == 0) & (img12_sq_sum_mul ~= 0);
quality_map(index) = 2*img12_sum_mul(index)./img12_sq_sum_mul(index);
index = (denominator ~= 0);
quality_map(index) = numerator(index)./denominator(index);
quality = mean2(quality_map);