How to keep specific colors and remove rest ?

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
9428949494
Posts: 1
Joined: 2013-01-09T01:07:27-07:00
Authentication code: 6789

How to keep specific colors and remove rest ?

Post by 9428949494 »

Image
You can see the image i just wish to keep two colors
color 1 -#609018
color 2- #489000 and remove all rest colors.

Whats the best way to do it ?

I searched a lot in the forum but couldnt find any better way to do it.

Thanks for help in advance.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to keep specific colors and remove rest ?

Post by Bonzo »

You do not realy give enough information but with what you have given you could either create a mask for the colours you want to keep or change the colours of the ones you do not want.

Example of the second method - you may be able to do the red and black in the same command.

Code: Select all

convert -fill white -fuzz 10% -opaque red output.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to keep specific colors and remove rest ?

Post by fmw42 »

try the following. make an image for each color and make everything but that color transparent (none). Then combine the images.

Note your hex colors are way off with regard to the image you posted. The following is a unix IM command. For windows, change the \( to ( and the same for \) to ) and change the line ending \ to ^. Also change % to %%. See http://www.imagemagick.org/Usage/windows/. Generally a good idea when you post to a topic to include your IM version and platform.


convert qp5vz7.png \
\( -clone 0 -channel rgba -fuzz 10% -fill none +opaque "#62921E" \) \
\( -clone 0 -channel rgba -fuzz 10% -fill none +opaque "#208C09" \) \
-delete 0 -compose plus -composite -compose over -background white -flatten qp5vz7_result.png

I assume the labeling of the hex colors inside the ellipse will be removed; otherwise you need to keep black as well and then distinguishing the labels from the black ellipse will require another solution.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to keep specific colors and remove rest ?

Post by anthony »

This should really be in users forum, not IM developers.

However... IM Examples to the rescue...
http://www.imagemagick.org/Usage/color_ ... z_distance

This example is really about the Fuzz factor, but it demonstrates a number of techniques of matching (keeping or removing) a list of colors.

Another technique is to use a HALD table, though that is probably better for removing for a very odd shaped swath of colors.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply