马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
下面的MATLAB程序计算两幅图像的加权峰值信噪比。相比常用的PSNR而言,考虑到HVS(human visual sytem)的影响。<br><br>function f = WPSNR(A,B,varargin)<br><br>% This function computes WPSNR (weighted peak signal-to-noise ratio) between<br>% two images. The answer is in decibels (dB).<br>%<br>% Using contrast sensitivity function (CSF) to weight spatial frequency<br>% of error image.<br>%<br>% Using: WPSNR(A,B)<br>%<br>% Written by Ruizhen Liu, http://www.assuredigit.com<br><br> if A == B<br> error('Images are identical: PSNR has infinite value')<br> end<br><br> max2_A = max(max(A));<br> max2_B = max(max(B));<br> min2_A = min(min(A));<br> min2_B = min(min(B));<br><br> if max2_A > 1 | max2_B > 1 | min2_A < 0 | min2_B < 0<br> error('input matrices must have values in the interval [0,1]')<br> end<br><br> e = A - B;<br> if nargin<3<br> fc = csf; % filter coefficients of CSF<br> else<br> fc = varargin{1};<br> end<br> ew = filter2(fc, e); % filtering error with CSF<br> <br> decibels = 20*log10(1/(sqrt(mean(mean(ew.^2)))));<br>% disp(sprintf('WPSNR = +%5.2f dB',decibels))<br> f=decibels;<br><br>%=============<br>function fc = csf()<br>%=============<br>% Program to compute CSF<br>% Compute contrast sensitivity function of HVS<br>%<br>% Output: fc --- filter coefficients of CSF<br>%<br>% Reference:<br>% Makoto Miyahara<br>% "Objective Picture Quality Scale (PQS) for Image Coding"<br>% IEEE Trans. on Comm., Vol 46, No.9, 1998.<br>%<br>% Written by Ruizhen Liu, http://www.assuredigit.com<br><br> % compute frequency response matrix<br> Fmat = csfmat;<br><br> % Plot frequency response<br> %mesh(Fmat); pause<br><br> % compute 2-D filter coefficient using FSAMP2<br> fc = fsamp2(Fmat); <br> %mesh(fc)<br><br><br>%========================<br>function Sa = csffun(u,v)<br>%========================<br>% Contrast Sensitivity Function in spatial frequency<br>% This file compute the spatial frequency weighting of errors<br>%<br>% Reference:<br>% Makoto Miyahara<br>% "Objective Picture Quality Scale (PQS) for Image Coding"<br>% IEEE Trans. on Comm., Vol 46, No.9, 1998.<br>%<br>% Input : u --- horizontal spatial frequencies<br>% v --- vertical spatial frequencies<br>% <br>% Output: frequency response<br>%<br>% Written by Ruizhen Liu, http://www.assuredigit.com<br><br> % Compute Sa -- spatial frequency response<br> %syms S w sigma f u v<br> sigma = 2;<br> f = sqrt(u.*u+v.*v);<br> w = 2*pi*f/60;<br> Sw = 1.5*exp(-sigma^2*w^2/2)-exp(-2*sigma^2*w^2/2);<br><br> % Modification in High frequency<br> sita = atan(v./(u+eps));<br> bita = 8;<br> f0 = 11.13;<br> w0 = 2*pi*f0/60;<br> Ow = ( 1 + exp(bita*(w-w0)) * (cos(2*sita))^4) / (1+exp(bita*(w-w0)));<br><br> % Compute final response<br> Sa = Sw * Ow;<br><br><br>%===================<br>function Fmat = csfmat()<br>%===================<br>% Compute CSF frequency response matrix<br>% Calling function csf.m<br>% frequency range<br>% the rang of frequency seems to be:<br>% w = pi = (2*pi*f)/60<br>% f = 60*w / (2*pi), about 21.2<br>%<br> min_f = -20;<br> max_f = 20;<br> step_f = 1;<br> u = min_f:step_f:max_f; <br> v = min_f:step_f:max_f;<br> n = length(u);<br> Z = zeros(n);<br> for i=1:n<br> for j=1:n<br> Z(i,j)=csffun(u(i),v(j)); % calling function csffun<br> end<br> end<br> Fmat = Z;<br>
[此贴子已经被作者于2005-10-15 15:13:53编辑过]
|