PSNR Calculation without using function

조회 수: 38 (최근 30일)
Aiswarya C B
Aiswarya C B 2020년 2월 9일
댓글: Aiswarya C B 2020년 2월 10일
I have calculated PSNR value for an input image and its ground truth without using psnr function. I have written the following code but three different values are obtained as output.
Here's my code.
I=imread('input.png');
ref=imread('groundTruth.png');
n=size(I);
M=n(1);
N=n(2);
MSE = sum(sum((I-ref).^2))/(M*N);
PSNR = 10*log10(256*256/MSE);
fprintf('\nPSNR value of image %9.7f dB', PSNR);
The output is obtained as follows:
PSNR value of image 32.6656113 dB
PSNR value of image 32.7511297 dB
PSNR value of image 32.7349438 dB>>
Which value is correct ? Why I'm getting these three outputs ?

채택된 답변

Subhadeep Koley
Subhadeep Koley 2020년 2월 10일
You are getting 3 PSNR values because your "input.png" and "groundTruth.png" are 3 channel RGB images and your code is calculating PSNR for each channel individually. You can convert your RGB image to grayscale before PSNR calculation to solve this issue. Refer the code below.
% Read the original image and add gaussian noise
I = imnoise(imread('peppers.png'), 'gaussian');
% RGB to gray conversion
I = rgb2gray(I);
% Read the original image
ref = imread('peppers.png');
% RGB to gray conversion
ref = rgb2gray(ref);
n = size(I);
M = n(1);
N = n(2);
% MSE calculation
MSE_val = sum(sum((I-ref).^2)) / (M*N);
% PSNR calculation
PSNR_val = 10*log10((256*256) / MSE_val);
fprintf('PSNR value of image %9.7f dB\n', PSNR_val);
Hope this helps!
  댓글 수: 1
Aiswarya C B
Aiswarya C B 2020년 2월 10일
Thank you so much.. This helps !!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by