MATLAB: Root mean square error of two images

image processingroot mean square error

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');
>> pog = sqrt(mean((J-I).^2));
>> message = sprintf('The Root mean square error is %.3f.', pog);
>> msgbox(message);
but i get a error string error computing that, but the message box variable does show the root sqaure 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

Best Answer

  • 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);