[SOLVED] Convert non-black pixels to white

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
dstrout
Posts: 2
Joined: 2010-10-26T06:29:50-07:00
Authentication code: 8675308

[SOLVED] Convert non-black pixels to white

Post by dstrout »

I am trying to process JPEG images that contain two letters that are nearly black, on a background that is nearly white. I have managed to make the letters fully black, and the background fully white by using white-threshold and black-threshold. However, the images also have little "squiggles" in them that are a darker gray color. I am wanting to remove these, and make them just white. Therefore, I was wondering if there is any way to, after fixing the letters and the background, just make all pixels that are not black, white. I have tried setting the white-threshold to 100%, but that does not work. Any other ideas?

And yes, this is a CAPTCHA, but this is just an experimental project. I am not hacking anything.
Last edited by dstrout on 2010-10-26T11:53:53-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert non-black pixels to white

Post by fmw42 »

First, to get pure black and white and no grays, you want to just use -threshold.

Second, if you really want to change all colors that are not say black to white, then use -fill white +opaque black

see

http://www.imagemagick.org/script/comma ... #threshold
http://www.imagemagick.org/script/comma ... php#opaque
dstrout
Posts: 2
Joined: 2010-10-26T06:29:50-07:00
Authentication code: 8675308

Re: Convert non-black pixels to white

Post by dstrout »

Thank you very much! That did the trick. Oh, and BTW, I knew I could just use -threshold, but I needed to set individual thresholds for black and white, otherwise it didn't work properly.

Thanks again!
Post Reply