How to Find MSE and PSNR ?

1 view (last 30 days)
Akbar Ramadhan
Akbar Ramadhan on 2 Mar 2021
Answered: Yash on 2 Dec 2023
Please help me, an error occurred when I was calculating the score of MSE and PSNR
“Error using -
Integers can only be combined with integers of the same class, or scalar doubles.”
I use an MSE and PSNR function like the following:
function [nilaiMSE, nilaiPSNR] = MSE_PSNR(citra_Prepro,citra_Process);
%MSE
[m, n] = size(citra_Process);
nilaiMSE = sum(sum(citra_Prepro - (citra_Process .^2))/(m*n));
%PSNR
nilaiPSNR = 10*log10(255*255/(nilaiMSE));
end
And I used to look for the following value:
citra_Prepro= getimage(handles.axes_Preview);
citra_Process= getimage(handles.axes_IHPF);
[nilaiMSE, nilaiPSNR]= MSE_PSNR(citra_Prepro,citra_Process);
set(handles.MSE_IHPF,'String', nilaiMSE);
set(handles.PSNR_IHPF,'String', nilaiPSNR);
where my "citra_Prepro" variables gets from histogram equalization and my "citra_Process" variables gets from Ideal High Pass Filter.

Answers (1)

Yash
Yash on 2 Dec 2023
Hi Akbar,
The error message you are getting suggests that there is a type mismatch between the citra_Prepro and citra_Process variables. Specifically, it seems that one of the variables is an integer and the other is a double. To fix this, you can convert both variables to the same data type using the double function. Here's an updated version of the MSE_PSNR function:
function [nilaiMSE, nilaiPSNR] = MSE_PSNR(citra_Prepro,citra_Process)
%MSE
c_Prepro = double(citra_Prepro);
citra_Process = double(citra_Process);
[m, n] = size(citra_Process);
nilaiMSE = sum(sum((citra_Prepro - citra_Process).^2))/(m*n);
%PSNR
nilaiPSNR = 10*log10(255*255/(nilaiMSE));
end
This version of the function converts both input variables to doubles using the double function, which should resolve the type mismatch error.

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!