Compute variance between two images

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
hwttdz
Posts: 22
Joined: 2010-08-29T05:29:08-07:00
Authentication code: 8675308

Compute variance between two images

Post by hwttdz »

I'd like to make a sort of fuzzy compare between two images (A and B, with dimensions x,y). In order to do this I'd like to compute the variance between the two images where

variance = sum over (x,y) { [red(A(x,y))-red(B(x,y))]^2+[green(A(x,y))-green(B(x,y))]^2+[blue(A(x,y))-green(B(x,y))]^2 }/(x*y)

I think there must be a reasonably quick way to do this but thus far the best I've come up with is to output both A and B as text files and then go to work on it with an external program.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Compute variance between two images

Post by fmw42 »

compare -metric rmse image1 image2 null:


gives you the square root of the mean squared error, which is similar to what you are asking (barring the square root). So perhaps you can take that result and use some -fx calculation to square it to get close to your variance.

see compare statistics at http://www.imagemagick.org/Usage/compare/#compare
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Compute variance between two images

Post by anthony »

the 'mse' (mean square error) is the same as 'rmse' just does not do the final square root.

See Compare Statistics (raw notes)
http://www.imagemagick.org/Usage/compare/#statistics
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply