Search code examples
matlabimage-enhancement

Negative value for PSNR after image enhancment in MATLAB


I have done this so far. After image enhancement in frequency domain for assessment, I have calculated PSNR. The value of PSNR and SNR is negative.

Further, the class of input and output image is double.

ref = imread('img.tif');
ref=im2double(ref);
%A = processing(ref);
%Calculate the PSNR.
[peaksnr, snr] = psnr(A, ref);

Can someone help me further?


Solution

  • I think you are converting ref into double, why are you converting it into double? psnr will never be negative as per the definition PSNR

    Please try these code first and then into your problem:

    ref = imread('pout.tif');
    A = imnoise(ref,'salt & pepper', 0.02);
    % Calculate the PSNR.
    [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);
    

    Out of the above code is:

    The Peak-SNR value is 22.6437
    The SNR value is 15.5524 
    

    In your case, just try following:

    ref = imread('img.tif');
    A = processing(im2double(ref));% what does it do?
    % Check the type of A, is it uint8 data type, if not then convert it to that 
    %Calculate the PSNR.
    [peaksnr, snr] = psnr(uint8(A), ref);
    

    Hope this will help you.