\(\)\(\)
Peak signal-to-noise ratio (PSNR) shows the ratio between the maximum possible power of a signal and the power of the same image with noise. PSNR is usually expressed in logarithmic decibel scale.
\( MSE =1/m*n \sum_{i=0}^{m-1} \sum_{j=0}^{n-1} [ Image( i,j) -NoisyImage( i,j) ] ^2 \)
\( PSNR =10* \log_{10} \Bigg(MAXI^2/MSE\Bigg) \)
MSE is Mean Square Error and MAXI is the maximum possible pixel value of the image. For instance if the image is uint8, it will be 255.
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 |
ref = imread('pout.tif'); A = imnoise(ref,'salt & pepper', 0.02); %%%%%%%%%%%%%%%%or we can apply gaussian noise%%%%%%%%%%%%%%%% %A = imnoise(ref, 'gaussian', 0, 0.003); [M,N]=size(ref); SE = (double(A) - double(ref)) .^ 2; % Squared Error MSE=sum( sum( SE ) ) /(M*N); %Mean Square Error MAXI=255; fprintf('\n PSNR is:') 10*log10((MAXI^2)/MSE) figure,imshow(A, []); figure,imshow(ref, []); figure,imshow(SE, []); %%%%%%%%%%%%%%%%% using Matlab API %%%%%%%%%%%%%%%% %MSE = immse(A, ref) [peaksnr, snr] = psnr(A, ref); fprintf('\n The Peak-SNR value is %0.4f', peaksnr); fprintf('\n The SNR value is %0.4f \n', snr); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
double getPSNR(const Mat& I1, const Mat& I2) { Mat s1; absdiff(I1, I2, s1); // |I1 - I2| s1.convertTo(s1, CV_32F); // cannot make a square on 8 bits s1 = s1.mul(s1); // |I1 - I2|^2 Scalar s = sum(s1); // sum elements per channel double sse = s.val[0] + s.val[1] + s.val[2]; // sum channels if( sse <= 1e-10) // for small values return zero return 0; else { double mse =sse /(double)(I1.channels() * I1.total()); double psnr = 10.0*log10((255*255)/mse); return psnr; } } |