【圖像評價】基于無參考NIQE圖像質量評價matlab源碼
一、簡介
新的模型稱之為NIQE(Natural Image Quality Evaluator),這個模型的設計思路是基于構建一系列的用于衡量圖像質量的特征,并且將這些特征用于擬合一個多元的高斯模型,這些特征是從一些簡單并且高度規(guī)則的自然景觀中提??;這個模型實際上是衡量一張待測圖像在多元分布上的差異,這個分布是有一系列的正常的自然圖像中提取的這些特征所構建的。
1 構建模型
空間域上的特征,稱之為Spatial Domain NSS
按照如下的方式進行計算,首先是提取圖像中的一個個patch,然后做下面這樣的一個歸一化

這里的μ \muμ就是高斯權重,在最初的設計中這里的高斯權重是一個3x3的模板;看到上面的公式,這里就很明確了,上述實際上一個基于高斯平均值以及高斯標準差的一個歸一化計算,相對于其他的一些指標,NIQE僅僅是計算正常的自然圖像中的這個指標,毫無疑問的是不正常的圖像多多少少會在這個指標上同正常圖像的計算值會有一個歧離,從這個意義上講,理論上NSS 可以適用于各種圖像退化種類,基于這種思想設計的IQA可以權衡各種圖像退化,而不是像某些指標那樣僅僅是在某些退化種類上有很好的的表現(xiàn)。
patch的選擇
如果需要計算上述的NSS指標,毫無疑問的是會造成圖像被分裂為一個一個的patch,在NIQE的算法設計中,只有一部分patch是有用的,這就涉及到一個patch的選擇問題;這里實際上有一個啟發(fā),比如我們關注一個分辨率退化圖像時,我們會挑選那些原本應該是sharp的局部邊緣進行觀察,判斷其分辨率是否受損,而不會整個圖像的所有patch都觀察一遍;這里定義了一種局部形變系數(shù)

這里的形變系數(shù)設置了一個閾值,在作者的實驗中,這個閾值設置的是0.75,大于0.75的patch 可以選入進行下一步計算;這一步的操作是很好理解的,因為畢竟往往是形變系數(shù)越大的patch說明里面的內(nèi)容越復雜,換而言之說明這里的內(nèi)容所包含的信息更多。這里的σ \sigmaσ就是上面步驟所述的σ \sigmaσ計算
描述patch
之前的內(nèi)容已經(jīng)說明了patch的空間域特征以及如何選擇patch,現(xiàn)在的問題在于如何設計指標來刻畫我們選擇的patch,這種刻畫按照設計是一種借鑒高斯分布思想的指標,首先定義高斯分布類型的指標GGD



二、源代碼
function ?[mu_prisparam cov_prisparam] ?= estimatemodelparam(folderpath,...
? ?blocksizerow,blocksizecol,blockrowoverlap,blockcoloverlap,sh_th)
? ?
% Input
% folderpath ? ? ?- Folder containing the pristine images
% blocksizerow ? ?- Height of the blocks in to which image is divided
% blocksizecol ? ?- Width of the blocks in to which image is divided
% blockrowoverlap - Amount of vertical overlap between blocks
% blockcoloverlap - Amount of horizontal overlap between blocks
% sh_th ? ? ? ? ? - The sharpness threshold level
%Output
%mu_prisparam ?- mean of multivariate Gaussian model
%cov_prisparam - covariance of multivariate Gaussian model
% Example call
%[mu_prisparam cov_prisparam] = estimatemodelparam('pristine',96,96,0,0,0.75);
%----------------------------------------------------------------
% Find the names of images in the folder
current = pwd;
cd(sprintf('%s',folderpath))
names ? ? ? ?= ls;
names ? ? ? ?= names(3:end,:);%
cd(current)
% ---------------------------------------------------------------
%Number of features
% 18 features at each scale
featnum ? ? ?= 18;
% ---------------------------------------------------------------
% Make the directory for storing the features
mkdir(sprintf('local_risquee_prisfeatures'))
% ---------------------------------------------------------------
% Compute pristine image features
for itr = 1:size(names,1)
itr
im ? ? ? ? ? ? ? = imread(sprintf('%s\\%s',folderpath,names(itr,:)));
if(size(im,3)==3)
im ? ? ? ? ? ? ? = rgb2gray(im);
end
im ? ? ? ? ? ? ? = double(im); ? ? ? ? ? ?
[row col] ? ? ? ?= size(im);
block_rownum ? ? = floor(row/blocksizerow);
block_colnum ? ? = floor(col/blocksizecol);
im ? ? ? ? ? ? ? = im(1:block_rownum*blocksizerow, ...
? ? ? ? ? ? ? ? ? 1:block_colnum*blocksizecol); ? ? ? ? ? ? ?
window ? ? ? ? ? = fspecial('gaussian',7,7/6);
window ? ? ? ? ? = window/sum(sum(window));
scalenum ? ? ? ? = 2;
warning('off')
feat = [];
for itr_scale = 1:scalenum
? ?
mu ? ? ? ? ? ? ? ? ? ? ? = imfilter(im,window,'replicate');
mu_sq ? ? ? ? ? ? ? ? ? ?= mu.*mu;
sigma ? ? ? ? ? ? ? ? ? ?= sqrt(abs(imfilter(im.*im,window,'replicate') - mu_sq));
structdis ? ? ? ? ? ? ? ?= (im-mu)./(sigma+1);
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
feat_scale ? ? ? ? ? ? ? = blkproc(structdis,[blocksizerow/itr_scale blocksizecol/itr_scale], ...
? ? ? ? ? ? ? ? ? ? ? ? ? [blockrowoverlap/itr_scale blockcoloverlap/itr_scale], ...
? ? ? ? ? ? ? ? ? ? ? ? ? @computefeature);
feat_scale ? ? ? ? ? ? ? = reshape(feat_scale,[featnum ....
? ? ? ? ? ? ? ? ? ? ? ? ? size(feat_scale,1)*size(feat_scale,2)/featnum]);
feat_scale ? ? ? ? ? ? ? = feat_scale';
if(itr_scale == 1)
sharpness ? ? ? ? ? ? ? ?= blkproc(sigma,[blocksizerow blocksizecol], ...
? ? ? ? ? ? ? ? ? ? ? ? ? [blockrowoverlap blockcoloverlap],@computemean);
sharpness ? ? ? ? ? ? ? ?= sharpness(:);
end
feat ? ? ? ? ? ? ? ? ? ? = [feat feat_scale];
im =imresize(im,0.5);
end
function ?quality = computequality(im,blocksizerow,blocksizecol,...
? ?blockrowoverlap,blockcoloverlap,mu_prisparam,cov_prisparam)
?
% Input1
% im ? ? ? ? ? ? ?- Image whose quality needs to be computed
% blocksizerow ? ?- Height of the blocks in to which image is divided
% blocksizecol ? ?- Width of the blocks in to which image is divided
% blockrowoverlap - Amount of vertical overlap between blocks
% blockcoloverlap - Amount of horizontal overlap between blocks
% mu_prisparam ? ?- mean of multivariate Gaussian model
% cov_prisparam ? - covariance of multivariate Gaussian model
% For good performance, it is advisable to use make the multivariate Gaussian model
% using same size patches as the distorted image is divided in to
% Output
%quality ? ? ?- Quality of the input distorted image
% Example call
%quality = computequality(im,96,96,0,0,mu_prisparam,cov_prisparam)
% ---------------------------------------------------------------
%Number of features
% 18 features at each scale
featnum ? ? ?= 18;
%----------------------------------------------------------------
%Compute features
if(size(im,3)==3)
im ? ? ? ? ? ? ? = rgb2gray(im);
end
im ? ? ? ? ? ? ? = double(im); ? ? ? ? ? ? ? ?
[row col] ? ? ? ?= size(im);
block_rownum ? ? = floor(row/blocksizerow);
block_colnum ? ? = floor(col/blocksizecol);
im ? ? ? ? ? ? ? = im(1:block_rownum*blocksizerow,1:block_colnum*blocksizecol); ? ? ? ? ? ? ?
[row col] ? ? ? ?= size(im);
block_rownum ? ? = floor(row/blocksizerow);
block_colnum ? ? = floor(col/blocksizecol);
im ? ? ? ? ? ? ? = im(1:block_rownum*blocksizerow, ...
? ? ? ? ? ? ? ? ? 1:block_colnum*blocksizecol); ? ? ? ? ? ? ?
window ? ? ? ? ? = fspecial('gaussian',7,7/6);
window ? ? ? ? ? = window/sum(sum(window));
scalenum ? ? ? ? = 2;
warning('off')
feat ? ? ? ? ? ? = [];
三、運行結果

