Page 1 of 1

How to remove or make transparent all but one single color.

Posted: 2008-05-22T18:33:34-07:00
by CannedCheese
I'm attempting to save an alphabet of bmps (or any format) of some all gray text characters and numbers that I have to screen capture in front of various backgrounds. The characters are always the exact same shade of Gray (0xC0C0C0C). Is there a way to remove or make transparent all colors that don't match this shade of gray? This is for optical character recognition purposes.

Cliff Notes: I want pure gray solid characters and to remove all background colors.

Re: How to remove or make transparent all but one single color.

Posted: 2008-05-22T19:09:50-07:00
by fmw42

Re: How to remove or make transparent all but one single color.

Posted: 2008-05-23T00:48:50-07:00
by Bonzo
Try this:

Code: Select all

convert original_image.jpg -matte ( +clone -fuzz 20% -transparent rgb(38,134,71) ) -compose DstOut -composite output.png

Re: How to remove or make transparent all but one single color.

Posted: 2008-05-27T11:40:48-07:00
by CannedCheese
I appreciate the response. I'm unaware of where to download a compiled version of the beta (I no longer have the compiler to compile the beta on my own). I've searched the faq and googled, etc-- is there a location to download a compiled version of the betas that runs on XP?

Re: How to remove or make transparent all but one single color.

Posted: 2008-05-27T11:41:24-07:00
by CannedCheese
Bonzo wrote:Try this:

Code: Select all

convert original_image.jpg -matte ( +clone -fuzz 20% -transparent rgb(38,134,71) ) -compose DstOut -composite output.png
Thanks, I will try this tonight as well.

Re: How to remove or make transparent all but one single color.

Posted: 2008-05-27T12:08:53-07:00
by fmw42
IM 6.4.1-4 is still not out yet. But you can get binary versions from http://www.imagemagick.org/script/binary-releases.php and source from http://www.imagemagick.org/download/www ... ource.html

Re: How to remove or make transparent all but one single color.

Posted: 2008-05-27T14:39:03-07:00
by CannedCheese
fmw42 wrote:IM 6.4.1-4 is still not out yet. But you can get binary versions from http://www.imagemagick.org/script/binary-releases.php and source from http://www.imagemagick.org/download/www ... ource.html
So there's no compiled beta to be downloaded from ftp://ftp.fifi.org/pub/ImageMagick/beta ?

Re: How to remove or make transparent all but one single color.

Posted: 2008-05-27T17:37:56-07:00
by fmw42
Not that I know of - only source beta that you need to compile.

Re: How to remove or make transparent all but one single color.

Posted: 2008-06-04T23:11:07-07:00
by anthony
Use +opaque which inverts the meaning of the color selection. That is replace pixels which are NOT this color (or near this color according to the fuzz factor.

This was added to IM v6.3.7-10 see Replace a Specific Color
Those examples also gives the same solution as above for IM versions pre-dating this addition.

in 2015 imagemagick on mac above didn't work but this did:

Posted: 2015-06-13T15:56:35-07:00
by dovo329
#To make all other colors in picture except red transparent:

convert input.png -transparent 'rgb(255,0,0)' matteInput.png
convert input.png -matte matteInput.png -compose DstOut -composite output.png

Re: How to remove or make transparent all but one single color.

Posted: 2015-06-13T18:49:57-07:00
by fmw42
try +transparent

Code: Select all

convert input.png +transparent red result.png
This will make everything but pure red transparent