%[mean] vs verbose info for a specific channel

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
benjay

%[mean] vs verbose info for a specific channel

Post by benjay »

Hi

I want to find out the mean of a specific channel (red, in this case). But doing this

Code: Select all

identify -format "%[mean]" -channel Red image.png
returns a number that does not correspond to my own calculation. (It returns 29126.7, but it should be 6.2222 instead)
I used a 3 by 3 pixel image, where I calculated the mean by hand.

On the opposite, if I do this:

Code: Select all

identify -verbose image.png
the numbers for the mean value under Red, Green and Blue do correspond to my results.
Shouldn't this be the same?
Thank you in advance
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: %[mean] vs verbose info for a specific channel

Post by fmw42 »

identify -format "%[mean]" info:

returns the global mean from all channels combined.

you want (so as to match the verbose info statistics)

identify -format "%[fx:mean.r] info:

to get the red channel. or mean.g or mean.b to get the green or blue channels.

Note that [fx:mean] returns values in the range 0 to 1 whereas [mean] returns values in range 0 to quantumrange (255 for 8-bit and 65535 for 16-bit IM compiles)
Post Reply