Monday, 1 June 2020

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 [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

Output:

PSNR =  25.1560


0 comments:

Post a Comment

Note: only a member of this blog may post a comment.