How to Calculate PSNR of Two Images with Different Sizes in MATLAB

To calculate the PSNR (Peak Signal-to-Noise Ratio) of two images with different sizes in MATLAB, you can follow these steps:

  1. Load the two images using the imread function.

 

img1 = imread('image1.jpg');
img2 = imread('image2.jpg');
  1. Convert the images to double precision using the im2double function.

 

img1 = im2double(img1);
img2 = im2double(img2);
  1. If the two images have different sizes, resize the larger image to the size of the smaller image using the imresize function.

 

if size(img1,1)*size(img1,2) > size(img2,1)*size(img2,2)
    img1 = imresize(img1, [size(img2,1) size(img2,2)]);
else
    img2 = imresize(img2, [size(img1,1) size(img1,2)]);
end
  1. Calculate the mean squared error (MSE) between the two images using the mse function.

 

mseValue = mse(img1, img2);
  1. Calculate the maximum pixel value using the max function.

 

maxPixelValue = max(max(img1));
  1. Calculate the PSNR using the following formula:

 

psnrValue = 20*log10(maxPixelValue/sqrt(mseValue));

The PSNR value represents the quality of the reconstructed image compared to the original image. A higher PSNR value indicates better image quality.

Note: The PSNR calculation assumes that the two images are of the same type (e.g., grayscale or RGB). If the two images are of different types, you need to convert them to the same type before performing the PSNR calculation.

Submit Your Programming Assignment Details