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.
Don
Version: ImageMagick 6.8.6-3 2013-06-25 Q16 http://www.imagemagick.org
Trying to get a file's average brightness level
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Trying to get a file's average brightness level
This should be the overall mean of all the channels of the image in range 0 to Quantumrange for your IM compile.identify -format "%[mean]\n" filename
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
see
http://www.imagemagick.org/script/fx.php
http://www.imagemagick.org/Usage/transform/#fx_escapes
http://www.imagemagick.org/script/escape.php
identify -format "%[mean]" rose:
27022.8
identify -format "%[fx:mean]" rose:
0.412342
identify -format "%[fx:quantumrange*mean]" rose:
27022.8
identify -depth 16 -verbose rose:
Overall:
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
Overall:
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
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
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.