what is matlab code for MSE and PSNR of 2 images?

7 views (last 30 days)
Image Processing

Answers (1)

Image Analyst
Image Analyst on 23 Oct 2016
Try this:
thePSNR = psnr(testImage, referenceImage);
theMSE = immse(testImage, referenceImage);
  4 Comments
RAKESH KUCHANA
RAKESH KUCHANA on 10 Apr 2021
clc;
x = imread('brain_mri(resized).png');
y = imread('brain_stego(resized).png');
Y1 = y;
[R,C] = size(Y1);
for i=2:R-1
for j=2:C-1
tmp = Y1(i-1:i+1, j-1:j+1);
if 0<Y1(i,j) && Y1(i,j)<255
Y1(i,j) = Y1(i,j);
else
b = sort(tmp(:));
b1 = b(b~=0);
b2 = b1(b1~=255);
b3 = mean(b2);
Y1(i,j) = b3;
end
end
end
subplot(1,3,1); imshow(x);
subplot(1,3,2); imshow(y);
subplot(1,3,3); imshow(Y1);
x = uint8(x);
y = uint8(y);
Y1 = uint8(Y1);
MXN = R*C;
MAE = (sum(sum(abs(((x)-(Y1))))))/MXN;
MSE = sum(sum(((x)-(Y1)).^2))/MXN;
PSNR = 10*log10(255^(2)/MSE);
gg = sum(sum(((double(y))-double(x))).^(2));
gg1 = sum(sum(((double(Y1))-double(x))).^(2));
IEF = gg./gg1;
val = ssim(Y1,x);
%Please verify this code, as I am getting error in bolded text line as "Matrix dimensions must agree & error in line 34". Solve this asap.
Image Analyst
Image Analyst on 11 Apr 2021
Never use size() like that on an image. Always have 3 output arguments just in case it's color. See Steve's blog for more on the reason for that:

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!