Page 1 of 1
Equation for MAE metric
Posted: 2016-01-14T03:18:10-07:00
by yannaos
//
Pick a black image RGB (0,0,0) and a white image (255,255,255) and calculate the difference
Code: Select all
compare -metric MAE black.png white png diff.png
65535 (1)
What is the mathematical operation that gives the 65535 result?
That is, what is the definition of the function below?
dist[ (0,0,0), (255,255,255) ] = 65535
Thanks for your time
Re: Equation for MAE metric
Posted: 2016-01-14T03:48:16-07:00
by dlemstra
Your white image is not (255,255,255) but (65535,65535,65535) because you are using the Q16 version of ImageMagick.
Re: Equation for MAE metric
Posted: 2016-01-14T04:08:59-07:00
by snibgo
It isn't a simple mathematical function, but a slightly complex algorithm, defined in compare.c.
It gives the mean absolute difference between two images, scaled to Quantum. "Mean" averages across both channels and pixels. The "absolute difference" is of course the larger minus the smaller. Pixel values are pre-multiplied by alpha.
In your example, which I suppose is Q16 so Quantum in 65535, 255-0 = 255, and if these are input maximum and minimum then the absolute difference for every channel for every pixel is Quantum. Hence the mean is also Quantum.
See also
http://www.imagemagick.org/script/comma ... php#metric
Re: Equation for MAE metric
Posted: 2016-01-14T05:48:07-07:00
by yannaos
>>
Thanks a lot dlemstra, snibgo,
I got it. My IM is indeed using QM 16.
With your information, I think I know now the equation that gives the first number in the output for -metric MAE, for the particular case of getting differences between 8bit/color PNG images (R,G,B) where each range is in interval [0,255].
So (in QM 16)
dist[ (R2,G2,B2), (R1,G1,B1) ] = (257/3)*( abs( R2 - R1) + abs( G2 - G1) + abs( B2 -B1) )
(Which by the way, that metric is called a taxi-cab (or Manhattan) metric.)
(And second number is just dist/65535)
Thanks again.
Re: Equation for MAE metric
Posted: 2016-01-14T06:03:57-07:00
by yannaos
>>
I saw my error after submission. See below. (Please correct if I am again wrong).
yannaos wrote:
dist[ (R2,G2,B2), (R1,G1,B1) ] = (257/3)*( abs( R2 - R1) + abs( G2 - G1) + abs( B2 -B1) )
.
should be:
dist[ image2 , image1 ] = (257/3)*( max( abs( R2 - R1)) + max( abs( G2 - G1) ) + max( abs( B2 -B1) ) )
where the max. is chosen between the corresponding pixels of both images.
Re: Equation for MAE metric
Posted: 2016-01-14T06:07:53-07:00
by snibgo
It's the mean, not the maximum.
Re: Equation for MAE metric
Posted: 2016-01-14T06:12:56-07:00
by yannaos
>>
snibgo wrote:It's the mean, not the maximum.
Thanks snibgo.
Third try then:
dist[ image2 , image1 ] = (257/3)*( mean( abs( R2 - R1)) + mean( abs( G2 - G1) ) + mean( abs( B2 -B1) ) )