## Wednesday, 5 February 2014

### How to Calculate PSNR (Peak Signal to Noise Ratio) in MATLAB?

Peak-Signal to Noise Ratio (PSNR)
1. The PSNR is most commonly used as a measure of quality of reconstruction of lossy compression codec’s (e.g., for image compression).
2. The signal in this case is the original data, and the noise is the error introduced by compression.
3. When comparing compression codec’s it is used as an approximation to human perception of reconstruction quality, therefore in some cases one reconstruction may appear to be closer to the original than another, even though it has a lower PSNR (a higher PSNR would normally indicate that the reconstruction is of higher quality).

The PSNR is calculated by using following formula.

MAXI=Maximum value of pixel in Original image
m=No. of Row in Original image
n= No. of Column in Original image

Procedure:
1. Read Original Image from current directory.
2. Read Noisy Image from current directory.
3. If Original Image is equal to Noisy Image then PSNR is 100%.
4. Find out difference between Original Image & Noisy Image.
5. Find out Mean Square Error by using above formula.
6. Find out maximum value of Pixel in Original Image.
7. Find out Peak Signal to Noise Ratio.

Program:
Function of PSNR
 function [psnr]=PSNR(I,K) I=double(I); K=double(K); if (I==K)     psnr=100; else     [r c p]=size(I);     d=0;     for i=1:r         for j=1:c             d=d+(I(i,j)-K(i,j))^2;         end     end     mse=d/(r*c);     maximum=max(I(:));     psnr=10*log10(maximum^2/mse); end

Test Application:
 clc [file path]=uigetfile('*.*'); I=imread(file); K = imnoise(I,'salt & pepper', 0.01); figure; subplot(1,2,1);imshow(I);title('Original Image') subplot(1,2,2);imshow(K);title('Noisy Image') [psnr]=PSNR(I,K); if(psnr<=30)     helpdlg('Image having low quality','Image Quality check box') elseif(psnr>=30 && psnr<=60)     helpdlg('Image having Medium quality','Image Quality check box') else     helpdlg('Image having good quality','Image Quality check box') end

Outputs:

Image Quality check box:

psnr =  25.1560

1. thanks for this post...:)

2. Can we calculate PSNR of 1-D signal? How to do that?

Thanks

1. yes we can.....its vary simple
1. first find the MSE of 1D signal
2. psnr=10log10(MAX^2/MSE) use this formula for finding PSNR

2. In this case, The MAX is the maximum value in the 1D Signal ??

3. Ya MAX is Maximum value in 1D signal...

4. Okk, but the maximum in the original signal ? or the noisy one ? or in both ?
Thank You !

5. Maximum from Original Signal...

6. Thank you a lot !
One last question
how can I compute SSIM (Structural Similarity index) for 1D Signals in matlab?

3. pls send d (.m) file

1. What is Your Email ID?

2. sir plz send me the code at sangwan_sudesh@yahoo.com as soon as possible.....

4. sir pease send me code for image quality metrics psnr mse ssim etc with read me file at shrepadzambodker88@gmail.com

5. all the image quality metrics codes average diffrence normalised absolute error

6. sir please send me the full code at e.ramya19@gmail.com

7. sir, please send me the full code at azlinazmahad@gmail.com.

Thank you