[magick-users] Determining predominant color using ImageMagick

Fred Weinhaus fmw at alink.net
Thu May 15 11:20:49 PDT 2008


It depends upon what you mean by predominant color.

If the image is 24-bit color, then you have real trouble as there are 
millions of colors and finding a single predominant color is not easy.

However, you can reduce the image down to a single pixel and get the 
color of that pixel. For example

convert rose: -resize 1x1 miff:- | convert - -format 
"rgb(%[fx:int(255*u.p{0,0}.r)],%[fx:int(255*u.p{0,0}.g)],%[fx:int(255*u.p{0,0}.b)])" 
info:



Or you may quantize the colors of the image to a reasonable number 
and then look at the histogram to find the most frequently used 
color.  See -colors



>I've got lost in the documentation and my google-fu has failed me.
>
>if I wanted to get the predominant color of an image, in order to base 
>a  CSS color scheme on an uploaded logo for example, how would I go 
>about doing that with ImageMagick?
>
>can it be done?
>
>TIA


More information about the Magick-users mailing list