Color Detection Of An Image

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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

I would probably do a color reduction to say 3 or so colors to find the basic colors used in an image. A histogram would then tell you which was the more common color.

Code: Select all

   convert image.png -colors 3 -depth 8 -format %c histogram:info:- 
For the built-in rose: image this showed that a darkish gray and a red were the premonident colors of this image.

Hmmm... this may be a good why of sorting images for comparision, or finding images of people with a predominate 'skin' color.

The number of colors may been adjustment. but should still work well.

NOTE that removing the outside borders of the image before looking for a predominate color may also be a very good idea.
Also you can use a -scale to get an average color!

Code: Select all

   convert image.png -gravity center -crop 70x70%+0+0 -scale 1x1\! -depth 8 txt:- 
I have not tried these except in a superficial way.
Please let me know what you discover, so that others can benifit and refine the methdos further.


I have added these notes to IM Examples Image Compare -- determining and sorting images...
http://www.cit.gu.edu.au/~anthony//grap ... #imagetype
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

The -segment option might be useful here. It analyzes the color histogram to find predominant mean colors in the image.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

yes -segment will quantize the colors but without limiting it to a specific number of colors. That is it will NOT merge two seperated sets of colors, just near-colors. that is something using -colors with a low number is prone to do.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Color Detection Of An Image

Post by anthony »

Additional...
I recently found an artical on what Color Segmentation is suposed to do....
http://www.leptonica.com/color-segmentation.html

The IM segementation algorithm does NOT do what this artical says it should do.
  1. The controls do not seem to make any realistic difference to output.
    That is, while you can get some differences between 1x1 and 1x2, the first
    number does not appear to have any effect, and beyond those numbers the
    second number also has a almost nill effect on the results.
  2. The results does not ignore things like black edges unless image is blurred first
  3. And -segment fails completely on images less than about 300x300 pixels.
    that is it will work (badly) on logo: (unless blured first), but it will just produce
    a single color for a image like rose:
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply