Keep only one color [color-spotting]

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
dognose
Posts: 265
Joined: 2005-03-08T22:16:37-07:00

Keep only one color [color-spotting]

Post by dognose »

I'm wondering if there is an easy way in IM to do something like this:

http://k47.pbase.com/u16/shaun/upload/2 ... eyes_r.jpg

Assuming the eyes were blue in an original color picture..
how could I remove all the other colors, but keep the blue?

I know about seeing the RGB channels of the image, but this seems different.

One way would be to select a color in the image +/- a fuzz, and convert everything else to grayscale.

Or, would there be a way to use a color map that only had blue and grayscale?

Any ideas on how to do this? I've gotten a lot of requests to do this type of effect.
Last edited by dognose on 2006-07-26T21:07:49-07:00, edited 2 times in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

One way I can think of, is to chnage all the blue colors (with a fuzz) to some other color, then compare the result with the original image. Every pixel that changed can then be used as a mask to extact all the blue pixels from the original image.

You can even trim down the resulting image using a fuzzy trim to remove the
small inconsequental spots of blues outside the main area.

NOTE your example image is NOT appearing.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
dognose
Posts: 265
Joined: 2005-03-08T22:16:37-07:00

Post by dognose »

Hmm,

Sorry, the site didn't allow direct linking I guess. If you copy and paste the url, it should work.

How would I "change all the blue colors, with a fuzz" ? If I can match all those colors and do a transformation, wouldn't it be easier to act on the other colors?

Is there a way to extract the color map from my example image and map that to a new image? Would come out as desired?
dognose
Posts: 265
Joined: 2005-03-08T22:16:37-07:00

Post by dognose »

Oh, just updated the original message... The effect in photoshop is callled "color-spotting"
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Hmm ok download the 'colorwheel' image
http://localhost/~anthony/graphics/imag ... rwheel.jpg

Now lets try to get all colors that are withing 30% spherical RGB distance to blue and make everything else transparent..

Code: Select all

  convert  colorwheel.jpg -matte \
              \( +clone  -fuzz 30% -transparent blue  \) \
              -compose DstOut -composite all_blue_colors.png
This copys the original image (adding an alpha/matte channel) and creates a mask of all the colors that was not blue, by trunign blue colors transparent. It then uses that image to find all the pixels that was not 'in' (eg teh destination pixels 'outside' the source image). That is the not-not-blue pixels. :-)
http://www.cit.gu.edu.au/~anthony/graph ... olor/#fuzz

The result is a image of all the blue-like colors, to the amount specified by the -fuzz factor.

I have added this example to the 'fuzz factor' section of 'Colors' in IM examples.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
dognose
Posts: 265
Joined: 2005-03-08T22:16:37-07:00

Post by dognose »

Wow, that works perfectly. Thanks!
Post Reply