imagemagickgraphicsmagickimagemagick-identify

Imagemagick GraphicsMagick image mean command


I use the following command that works in imagemagick to get the mean of a picture

identify -format "%[mean]" photo.jpg

the same command does not work under graphicsmagick. Is there an equivalent I can use?


Solution

  • You can do this, for example:

    gm identify -verbose photo.jpg | grep -E "Mean|Red|Green|Blue"
    

    Or, if you want Red, Green and Blue as 3 separate integers

    gm identify -verbose photo.jpg | awk '/Mean:/{s=s int($2) " "} END{print s}'
    0 29 225
    

    Or, if you want the average of all channels, like this:

    gm identify -verbose photo.jpg | awk '/Mean:/{n++;t+=$2} END{print int(t/n)}'
    85