# PSNR of two images of different size in matlab

I performed bicubic interpolation on a 256*256 image(img)

 dest = interp2(img,'bicubic')


and i got a 511 * 511 image.I want to compute PSNR of a 512 * 512 image(original) and the 'dest' image as follows

original = double(original);
dest = double(dest);
[M N] = size(original);
error = original - dest;
MSE = sum(sum(error .* error)) / (M * N);

if(MSE > 0)
PSNR = 10*log(255*255/MSE) / log(10);
disp(['PSNR = ', num2str(PSNR)])
else
PSNR = 99;
disp(['PSNR = ', num2str(PSNR)])
end


But I'm getting error due to different matrix dimensions.How to avoid this error.Is it possible to calculate PSNR of images with different size?Please help

## 1 Answer

When interpolating, why not use the same size as the image to compare with:

% some random inputs
original = rand(435,782);
img = rand(100,200);
% position where to interpolate
[x,y] = meshgrid(linspace(1,size(img,2),size(original,2)),linspace(1,size(img,1),size(original,1)));
% interpolate
dest = interp2(img,x,y,'bicubic');
% display size of result
disp(size(dest));