How to Find MSE and PSNR ?

1 次查看(过去 30 天)
Akbar Ramadhan
Akbar Ramadhan 2021-3-2
回答: Yash 2023-12-2
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.

回答(1 个)

Yash
Yash 2023-12-2
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.

产品


版本

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by