Average color

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
imagetester

Average color

Post by imagetester »

Is there any efficient way to get the average color of ANY image in a way to get Average Red=... Average Green=... Average Blue=...

And within the range 0-255 for each color.

I'm using magick++ library with c++
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Average color

Post by fmw42 »

convert this command line to magick++

convert rose: -scale 1x1! -depth 8 txt:-

returns
# ImageMagick pixel enumeration: 1,1,255,rgb
0,0: (145, 89, 80) #915950 rgb(145,89,80)

or

convert rose: -scale 1x1! -format "%[fx:floor(255*u.r)],%[fx:floor(255*u.g)],%[fx:floor(255*u.b)]" info:

returns
145,89,80
Post Reply