1 % =================================================================
\r
2 % Sparse Feature Fidelity (SFF) Version 2.0
\r
3 % Copyright(c) 2013 Hua-wen Chang
\r
4 % All Rights Reserved.
\r
5 % changhuawen@gmail.com
\r
6 % ----------------------------------------------------------------------
\r
7 % Permission to use, copy, or modify this software and its documentation
\r
8 % for educational and research purposes only and without fee is here
\r
9 % granted, provided that this copyright notice and the original authors'
\r
10 % names appear on all copies and supporting documentation. This program
\r
11 % shall not be used, rewritten, or adapted as the basis of a commercial
\r
12 % software or hardware product without first obtaining permission of the
\r
13 % authors. The authors make no representations about the suitability of
\r
14 % this software for any purpose. It is provided "as is" without express
\r
15 % or implied warranty.
\r
16 % ----------------------------------------------------------------------
\r
17 % Please refer to the following paper
\r
19 % Hua-wen Chang, Hua Yang, Yong Gan, and Ming-hui Wang, "Sparse Feature Fidelity
\r
20 % for Perceptual Image Quality Assessment", IEEE Transactions on Image Processing,
\r
21 % vol. 22, no. 10, pp. 4007-4018, October 2013
\r
22 % ----------------------------------------------------------------------
\r
24 % Ir: reference image
\r
25 % Id: distorted image
\r
26 % W: feature detector (in the file 'W.mat'
\r
27 % or can be generated by running 'TrainW' in \Training.)
\r
30 % load('W.mat'); % load feature detector W
\r
31 % score = SFF(refImage, disImage, W);
\r
32 % =================================================================
\r
34 function SFFscore = SFF(Ir, Id, W)
\r
36 patchSize = size(W,1); %8
\r
37 patchDim = (patchSize^2)*3;
\r
45 %%%%%% DIVIDING EACH IMAGE INTO BLOCKS %%%%%%
\r
47 sizeY = size(Ir,1); sizeX = size(Ir,2);
\r
48 gridY = startPosition : patchSize : sizeY-patchSize; %
\r
49 gridX = startPosition : patchSize : sizeX-patchSize; %
\r
50 Y = length(gridY); X = length(gridX);
\r
51 Xr = zeros(patchDim, Y*X);
\r
52 Xd = zeros(patchDim, Y*X);
\r
57 Xr(:,ij) = reshape( Ir(i:i+patchSize-1, j:j+patchSize-1, 1:3), [patchDim 1] );
\r
58 Xd(:,ij) = reshape( Id(i:i+patchSize-1, j:j+patchSize-1, 1:3), [patchDim 1] );
\r
63 Xr = double(Xr); Xd = double(Xd);
\r
64 mXr = mean(Xr); mXd = mean(Xd); % mean value
\r
66 Xr = Xr-ones(size(Xr,1),1)*mXr;
\r
67 Xd = Xd-ones(size(Xd,1),1)*mXd;
\r
70 % ========== [FEATURE SIMILARITY] ============
\r
71 % ---------- SELECTION OF PATCH PAIRS ----------
\r
72 Xe = mean(abs(Xr-Xd));
\r
73 medXe = Tx*median(Xe);
\r
74 Y_dis = Xd(:,Xe>=medXe);
\r
75 Y_ref = Xr(:,Xe>=medXe);
\r
77 % ------------- FEATURE EXTRACTION ------------
\r
78 A = W*Y_ref; B = W*Y_dis;
\r
80 % ------------- VISUAL THRESHOLD --------------
\r
81 responseIntensity = sum(A.^2);
\r
82 VT = Tv*mean(responseIntensity);
\r
83 A_th = A(:,responseIntensity>VT);
\r
84 B_th = B(:,responseIntensity>VT);
\r
86 % ------------- FEATURE SIMILARITY ------------
\r
88 C2 = A_th.^2+B_th.^2;
\r
89 SFF_f = mean2((2*C1+C)./(C2+C));
\r
93 % ========= [LUMINANCE CORRELATION] ==========
\r
94 % ------ SELECTION OF MEAN VALUE PAIRS ------
\r
96 mmXe = Tm*median(mXe);
\r
97 mXd = mXd(:,mXe>=mmXe);
\r
98 mXr = mXr(:,mXe>=mmXe);
\r
100 % ---------- LUMINANCE CORRELATION ----------
\r
101 meanXr = mXr-mean(mXr);
\r
102 meanXd = mXd-mean(mXd);
\r
103 SFF_m = (sum(meanXr.*meanXd)+Cm) / (sqrt(sum(meanXr.^2)*sum(meanXd.^2))+Cm);
\r
107 %%%%%%%%%%%% QUAITY SCORE %%%%%%%%%%%
\r
108 SFFscore = Lamda*SFF_m+(1-Lamda)*SFF_f;
\r