 # Grayscale Image Comparison Question

I would like to compare sets of images (a reference and a test image) pixel by pixel.

Specifically, I would like to calculate the absolute difference in grayscale value for each pixel and them sum the values.

For example, something like this…

For all i & j
Sum( ABS(Grayscale Value(Reference Image)i,j - Grayscale Value(test image)i,j))

I want to calculate the “relative error” or degree of how much the test image deviates from a reference image.

If you can’t tell, I don’t know Java and will have to learn it to be able to do this I guess…

What would be the best way to do this?
Is there a plug-in out there all ready that can do this?

Thanks.

Thanks Herbie. I’ll give it a try.

Hello Herbie,

I am also trying to determine the color difference between two images. The two images were taken at different light condition of the same object and had color patterns. From naked eye observation, they appeared to be same to me as I tried to identify some key features. I used your approach “image calculator, difference, square, square root” and the final square root value was around 20. (A big thank you.)The “difference” image looked mostly black with white patterns. My question is whether this 20 means significant difference between the two images. It is probably depending on my application which I have little clue as of now. If these difference images have 32 bit, does that mean the full color scale is 32*32=1024, so this 20 is merely 2% of difference?

Many thanks.

Dear,

color is a different issue and you are not to use an approach that was suggested for grayscale image comparisons to color images, except you know exactly what you are doing.

32*32=1024

This is far from reality …

Regards

Herbie

Thank you.
Then can I use this approach to compare the difference if I convert these pictures to grayscale?
If not, do you have any suggestions to compare color images?
Many thanks,

[…] if I convert these pictures to grayscale?

Why not?

In any case, it would be helpful to see a pair of images that you like to compare. Please post typical raw-images in TIFF- or PNG-format.

Regards

Herbie

I’d actually used exactly the approach Herbie suggested previously in a script …it ends up being only a few lines to calculate what you’re looking for in a script.

here is some of the code I’d used to do it

``````    imageCalculator("Difference create 32-bit", target, "Output");
rename("RMS");
run("Square");

selectWindow("RMS");

getStatistics(area, meanSqr);
rootMeanSqr = sqrt(meanSqr);

// normalise by dividing by max difference in pixel values between both images
selectWindow(source);
getStatistics(area,mean,min1,max1);
selectWindow(target);
getStatistics(area,mean,min2,max2);
minmin = minOf(min1, min2);
maxmax = maxOf(max1, max2);
norm = maxmax - minmin;

normRMS = rootMeanSqr / norm;``````