Skip to content

Commit

Permalink
Feature/add strred runner (#53)
Browse files Browse the repository at this point in the history
* Add matlab/strred.

* Make strred matlab cmd work.

* Add StrredFeatureExtractor and StrredQualityRunner.

* Update VERSION.
  • Loading branch information
li-zhi committed Dec 21, 2016
1 parent 2484486 commit 45ddff0
Show file tree
Hide file tree
Showing 191 changed files with 9,953 additions and 35 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# Change Log

## (12/20/2016) [1.1.20]

**New features:**
- Add STRRED runner.

## (12/19/2016) [1.1.19]

**New features:**
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
VMAF Development Kit (VDK) Version 1.1.19
VMAF Development Kit (VDK) Version 1.1.20
1 change: 1 addition & 0 deletions matlab/.gitignore
@@ -0,0 +1 @@
*~
23 changes: 23 additions & 0 deletions matlab/strred/README
@@ -0,0 +1,23 @@
** modifications **

(12/19/2016 zli@netflix.com) Three modifications are made to fit into the VDK framework:
1) Instead of specifying number of seconds to read, read file until the end.
2) Instead of calculating a frame score every two frames, change it to one score
every frame.
3) Original algorithm averages frame SRRED and TRRED scores first, and the final
STRRED score is the product of the two. In this modified version, only the per-
frame SRRED and TRRED scores are calculated and passed out. The computation of
the STRRED score is performed outside, by first computing the per-frame STRRED
score via:
per-frame STRRED = (per-frame SRRED) * (per-frame TRRED)
and then aggregating (e.g. via taking the mean).

** run **

Command run_strred takes in arguments:
ref_yuv_file_path dis_yuv_file_path width height

After installing Matlab and setting path, run STRRED in command line:
matlab -nodisplay -nosplash -nodesktop -r "run_strred('../../resource/yuv/src01_hrc00_576x324.yuv', '../../resource/yuv/src01_hrc01_576x324.yuv', 576, 324); exit;"


112 changes: 112 additions & 0 deletions matlab/strred/SR_SIM.m
@@ -0,0 +1,112 @@
function sim = SR_SIM(image1, image2)
% ========================================================================
% SR_SIM Index with automatic downsampling, Version 1.0
% Copyright(c) 2011 Lin ZHANG
% All Rights Reserved.
%
% ----------------------------------------------------------------------
% Permission to use, copy, or modify this software and its documentation
% for educational and research purposes only and without fee is hereQ
% granted, provided that this copyright notice and the original authors'
% names appear on all copies and supporting documentation. This program
% shall not be used, rewritten, or adapted as the basis of a commercial
% software or hardware product without first obtaining permission of the
% authors. The authors make no representations about the suitability of
% this software for any purpose. It is provided "as is" without express
% or implied warranty.
%----------------------------------------------------------------------
%
% This is an implementation of the algorithm for calculating the
% Spectral Residual based Similarity (SR-SIM) index between two images. For
% more details, please refer to our paper:
% Lin Zhang and Hongyu Li, "SR-SIM: A fast and high performance IQA index based on spectral residual", in: Proc. ICIP 2012.
%
%----------------------------------------------------------------------
%
%Input : (1) image1: the first image being compared
% (2) image2: the second image being compared
%
%Output: sim: the similarity score between two images, a real number
%
%-----------------------------------------------------------------------
[rows, cols, junk] = size(image1);
if junk == 3
Y1 = 0.299 * double(image1(:,:,1)) + 0.587 * double(image1(:,:,2)) + 0.114 * double(image1(:,:,3));
Y2 = 0.299 * double(image2(:,:,1)) + 0.587 * double(image2(:,:,2)) + 0.114 * double(image2(:,:,3));
else
Y1 = double(image1);
Y2 = double(image2);
end

%%%%%%%%%%%%%%%%%%%%%%%%%
% Download the image
%%%%%%%%%%%%%%%%%%%%%%%%%
minDimension = min(rows,cols);
F = max(1,round(minDimension / 256));
aveKernel = fspecial('average',F);

aveY1 = conv2(Y1, aveKernel,'same');
aveY2 = conv2(Y2, aveKernel,'same');
Y1 = aveY1(1:F:rows,1:F:cols);
Y2 = aveY2(1:F:rows,1:F:cols);

%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculate the visual saliency maps
%%%%%%%%%%%%%%%%%%%%%%%%%
saliencyMap1 = spectralResidueSaliency(Y1);
saliencyMap2 = spectralResidueSaliency(Y2);
%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculate the gradient map
%%%%%%%%%%%%%%%%%%%%%%%%%
dx = [3 0 -3; 10 0 -10; 3 0 -3]/16;
dy = [3 10 3; 0 0 0; -3 -10 -3]/16;
IxY1 = conv2(Y1, dx, 'same');
IyY1 = conv2(Y1, dy, 'same');
gradientMap1 = sqrt(IxY1.^2 + IyY1.^2);

IxY2 = conv2(Y2, dx, 'same');
IyY2 = conv2(Y2, dy, 'same');
gradientMap2 = sqrt(IxY2.^2 + IyY2.^2);

%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculate the SR-SIM
%%%%%%%%%%%%%%%%%%%%%%%%%
C1 = 0.40; %fixed
C2 = 225;
alpha = 0.50;%fixed

GBVSSimMatrix = (2 * saliencyMap1 .* saliencyMap2 + C1) ./ (saliencyMap1.^2 + saliencyMap2.^2 + C1);
gradientSimMatrix = (2*gradientMap1.*gradientMap2 + C2) ./(gradientMap1.^2 + gradientMap2.^2 + C2);

weight = max(saliencyMap1, saliencyMap2);
SimMatrix = GBVSSimMatrix .* (gradientSimMatrix .^ alpha) .* weight;
sim = sum(sum(SimMatrix)) / sum(weight(:));

return;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function saliencyMap = spectralResidueSaliency(image)
%this function is used to calculate the visual saliency map for the given
%image using the spectral residue method proposed by Xiaodi Hou and Liqing
%Zhang. For more details about this method, you can refer to the paper:
%Saliency detection: a spectral residual approach.

%there are some parameters needed to be adjusted
scale = 0.25; %fixed
aveKernelSize = 3; %fixed
gauSigma = 3.8; %fixed
gauSize = 10; %fixed

inImg = imresize(image, scale);

%%%% Spectral Residual
myFFT = fft2(inImg);
myLogAmplitude = log(abs(myFFT));
myPhase = angle(myFFT);

mySpectralResidual = myLogAmplitude - imfilter(myLogAmplitude, fspecial('average', aveKernelSize), 'replicate');
saliencyMap = abs(ifft2(exp(mySpectralResidual + 1i*myPhase))).^2;

%%%% After Effect
saliencyMap = mat2gray(imfilter(saliencyMap, fspecial('gaussian', [gauSize, gauSize], gauSigma)));
saliencyMap = imresize(saliencyMap,[size(image,1) size(image,2)]);

0 comments on commit 45ddff0

Please sign in to comment.