how to identify channel statistics with identify -format only

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
AlexPUA
Posts: 5
Joined: 2017-11-09T22:48:47-07:00
Authentication code: 1152
Location: Ukraine

how to identify channel statistics with identify -format only

Post by AlexPUA »

What is the format option(-s) to get info from "Channel statistics:" block of -verbose option without image conversions
Such as (for example)
identify -format "%f %[skewness]\n" filename.jpg
but for red (for example) channel - not for all image statistics
Channel statistics:
Pixels: 2920225
Red:
****
skewness: -1.67462
***
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 210.185 (0.824256)
standard deviation: 56.0961 (0.219985)
kurtosis: 1.51886
skewness: -1.45171
entropy: 0.700884
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to identify channel statistics with identify -format only

Post by fmw42 »

See http://www.imagemagick.org/script/escape.php. You need to use convert rather than identify to select the channel.

Code: Select all

convert filename.jpg -channel red -format "%f %[skewness]\n" info:
AlexPUA
Posts: 5
Joined: 2017-11-09T22:48:47-07:00
Authentication code: 1152
Location: Ukraine

Re: how to identify channel statistics with identify -format only

Post by AlexPUA »

Thanks a lot !
So, a got the way to get image composite and channels info in-one-line is (in Windows BAT format)
identify -format "%%f %%[width] %%[height] %%[size] %%[colors] %%[entropy] %%[kurtosis] %%[mean] %%[skewness] %%[standard-deviation] " %1 >> %1.iinfo
convert %1 -channel red -format "red %%[entropy] %%[kurtosis] %%[mean] %%[skewness] %%[standard-deviation] " info: >> %1.iinfo
convert %1 -channel green -format "green %%[entropy] %%[kurtosis] %%[mean] %%[skewness] %%[standard-deviation] " info: >> %1.iinfo
convert %1 -channel blue -format "blue %%[entropy] %%[kurtosis] %%[mean] %%[skewness] %%[standard-deviation]\n" info: >> %1.iinfo
It's not so fast (effective) as "identify -verbose" but it works
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to identify channel statistics with identify -format only

Post by snibgo »

If you put it all in one long "convert", you need run only one "convert", and read the image file once.

If you have multiple "-format" settings, you should "+write info" after each one.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to identify channel statistics with identify -format only

Post by fmw42 »

If you use fx statistics (relative to gray levels in the range 0 to 1), you can use channel specifiers. So for example:

Code: Select all

identify -format "rmean=%[fx:mean.r]\ngmean=%[fx:mean.g]\nbmean=%[fx:mean.b]\nrstd=%[fx:standard_deviation.r]\ngstd=%[fx:standard_deviation.g]\nbstd=%[fx:standard_deviation.b]\n" logo:
rmean=0.899307
gmean=0.887126
bmean=0.898288
rstd=0.271931
gstd=0.277917
bstd=0.25138

You can add skewness and kertosis also. See http://www.imagemagick.org/script/fx.php

You can also multiply by 255 if you want in the fx: brackets if you want to scale to the range 0 to 255
Post Reply