Common colors?

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?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Common colors?

Post by fmw42 »

In IM, HSV is -colorspace HSB. You can also use HSL (-colorspace HSL)
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Subdued brown vs. yellow

Post by anthony »

JoaCHIP wrote:I've found out that when comparing colors (like for example searching through a database with images), comparing colors in the HSV color space works much better.
The BIGGEST problem with using a HSV color space is that hue is a modulus color value. That is to say the Red hue is divided to become two extremes.

To handle this you may like to consider doing your color search in HSV and a HSV which has been rotated 180 degrees. If the two matches GOOD. But if you get two peaks at each extreme ends you will probably need to merge those peaks using the rotated color match.

I would like to see this technique developed further, Finding good common colors taken to extremes is a type of color segmentation (find extremes) and color quantization (best distribution of colors for dithering purposes).
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: Common colors?

Post by anthony »

GeekNeck wrote: Image

My eye tells me the dominant color is yellow but ImageMagick tells me the dominant color is a subdued brown

Code: Select all

$ convert 20100530_breakfast_steam_002.jpg -colors 16 -depth 8 -format "%c" histogram:info:|sort -rn|head -3
     78023: ( 16, 15, 11) #100F0B rgb(16,15,11)
     33536: ( 79, 40, 26) #4F281A rgb(79,40,26)
     26934: ( 44, 42, 36) #2C2A24 rgb(44,42,36)
The difference here is that you are wanting color segmention (widely spaced colors)...
To my eye this is yellow, redish-brown, a very dark green (window contents) and a dark grey (window frame). Prehaps even one light green for the small stripe of well lit curtain.

The normal IM -colors option (turn on verbose to see what it is doing) is not finding the widely spaced colors, but the best color distribution for dithering purposes. The two are similar but used for very different purposes.

For dithering purposes it found many yellows and dark greens as this is needed to produce the variations for dither purpose (the best distribution). Brown was the least variant so one brown is all that was needed color the most pixels. As such in you results you got a cluster of multiple yellows (not many pixels each) and a very large number of browns. Consequently brown was on top, even though it was not the most dominant (multiple shades of yellows).

The same thing happened in the previous image, with the red shirt. Only one red was found because it is not highly variable, so did not need many colors, The rest of the image had lots of subdued variations, requiring many colors to 'dither' properly.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply