Page 1 of 1

Trying to get a file's average brightness level

Posted: 2013-09-10T16:04:44-07:00
by dgpeters
The documentation isn't clear what this output actually calculates:

identify -format "%[mean]\n" filename

It sounds like it should be similar to the "Mean" values that come out of (the middle of) this command:

identify -verbose filename

But they aren't alike at all. Why are these statistics different when they have the same name?

The real underlying problem that I'm trying to solve is I want a computationally quick way to determine a "level of brightness" of a given file. And I have to do this at least 100 times per second. I find that piping the results of "identify -version" into awk to extract the mean intensity level is unable to meet my speed requirements. I was hoping that this "format" method might be faster. It might help if there was a built-in way to limit the output values of the "identify -verbose" command, but I can't find a way to do that.


Version: ImageMagick 6.8.6-3 2013-06-25 Q16

Re: Trying to get a file's average brightness level

Posted: 2013-09-10T16:11:56-07:00
by fmw42
identify -format "%[mean]\n" filename
This should be the overall mean of all the channels of the image in range 0 to Quantumrange for your IM compile.

If you want the values in the range 0 to 1, then use

identify -format "%[fx:mean]\n" filename

Both should be part of what you see in identify -verbose filename

If you want the mean of any given channel, then use

identify -format "%[fx:mean.r ]\n" filename

for the red channel

You can also multiply it by quantumrange to get the same as %[mean]

identify -format "%[fx:quantumrange*mean]\n" filename


identify -format "%[mean]" rose:

identify -format "%[fx:mean]" rose:

identify -format "%[fx:quantumrange*mean]" rose:

identify -depth 16 -verbose rose:
Depth: 16/8-bit
min: 5654 (0.0862745)
max: 65535 (1)
mean: 27022.8 (0.412341)
standard deviation: 15270.9 (0.233019)
kurtosis: 1.2733
skewness: 1.45983

If you do not add -depth 16 on Q16 IM, you may get depth 8 results, but the value in the range 0 to 1 will be the same.

identify -verbose rose:
Depth: 8-bit
min: 22 (0.0862745)
max: 255 (1)
mean: 105.147 (0.412341)
standard deviation: 59.4199 (0.233019)
kurtosis: 1.2733
skewness: 1.45983

105.147*65535/255 = 27022.779

Re: Trying to get a file's average brightness level

Posted: 2013-09-10T16:21:18-07:00
by dgpeters
Wow, that was fast and seems to be correct. I've been working all day on this (that's because I'm quite new to Image Magick). I thank you and I love you. Sleep well.

Re: Trying to get a file's average brightness level

Posted: 2013-09-29T20:08:12-07:00
by dgpeters
How curious!! The first word of my last post (shown as "???"") was, I recall, just a 3-letter polite word of surprise starting with "W". I'm guessing it was censored. Sorry about that.