Root mean square error of two images

11 ビュー (過去 30 日間)
Tey
Tey 2020 年 4 月 28 日
編集済み: Tey 2022 年 5 月 2 日
What is the function to calculate RSME of two images in matlab? i use:
I = imread('C:\Users\teymo\Desktop\New folder\CPU\rgray8.bmp');
J = imread('C:\Users\teymo\Desktop\New folder\CPU\blur.bmp');
result = sqrt(mean((J-I).^2));
message = sprintf('The Root mean square error is %.3f.', result);
msgbox(message);
but i get a error string error computing that, but the message box variable does show the root square but there are more than 1 number ?
"'The Root mean square error is 0.000.The Root mean square error is 2.848.The Root mean square error is 3.040.The Root mean square error is 3.056.The Root mean square error is 3.183.The Root mean square error is 3.350." It goes on forever so im not sure how to do it correctly

採用された回答

Rik
Rik 2020 年 4 月 28 日
Imagen in Matlab are either 2D or 3D. Assuming your images are already 2D, the subtraction will be element-wise, after which you have an element-wise square, followed by mean. The mean function only reduces by 1 dimension, so you end up with a vector. That means sqrt will be an element-wise operation, so pog is a vector.
If you want a single number, you need to convert your images to a vector:
I = imread('C:\Users\teymo\Desktop\New folder\CPU\rgray8.bmp');
J = imread('C:\Users\teymo\Desktop\New folder\CPU\blur.bmp');
pog = sqrt(mean((J(:)-I(:)).^2));
% ^^^ ^^^ add this
message = sprintf('The Root mean square error is %.3f.', pog);
msgbox(message);
  3 件のコメント
DGM
DGM 2022 年 5 月 2 日
編集済み: DGM 2022 年 5 月 2 日
Calculating RMSE (or MSE or MAD) directly on imported image data will likely be incorrect unless precautions are taken.
Most images are going to be integer-class, so the limited range of the numeric class will result in truncation when taking the difference and when squaring.
A = imread('peppers.png'); % these are both uint8
B = imnoise(A);
rmse1 = sqrt(mean((A(:)-B(:)).^2)) % direct calculation with integers
rmse1 = 9.1003
rmse2 = sqrt(mean((double(A(:))-double(B(:))).^2)) % convert to floats
rmse2 = 24.2077
rmse3 = sqrt(immse(A,B)) % or if you have IPT, you can just use immse()
rmse3 = 24.2077
Tey
Tey 2022 年 5 月 2 日
Thanks for the updates, that is correct. SSIM or IMMSE are good alternatives

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeometric Transformation and Image Registration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by