Equation for MAE metric

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
yannaos
Posts: 4
Joined: 2016-01-14T03:03:59-07:00
Authentication code: 1151

Equation for MAE metric

Post 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
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Equation for MAE metric

Post by dlemstra »

Your white image is not (255,255,255) but (65535,65535,65535) because you are using the Q16 version of ImageMagick.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Equation for MAE metric

Post 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
snibgo's IM pages: im.snibgo.com
yannaos
Posts: 4
Joined: 2016-01-14T03:03:59-07:00
Authentication code: 1151

Re: Equation for MAE metric

Post 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.
yannaos
Posts: 4
Joined: 2016-01-14T03:03:59-07:00
Authentication code: 1151

Re: Equation for MAE metric

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Equation for MAE metric

Post by snibgo »

It's the mean, not the maximum.
snibgo's IM pages: im.snibgo.com
yannaos
Posts: 4
Joined: 2016-01-14T03:03:59-07:00
Authentication code: 1151

Re: Equation for MAE metric

Post 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) ) )
Post Reply