Solved

ImageMagick: Greyscale to black and white conversion

Posted on 2004-04-23
7
5,231 Views
Last Modified: 2012-08-13
I have the latest ImageMagick installed on my server and I'm trying to figure out how I can take an extracted matte image (grayscale) and convert it to black and white in such a way that all pixels with a value between 0 and 254 are converted to 0 and all pixels with a value of 255 are left white.  In other words, for each pixel that is any level of grey, turn it black, any pixels that are pure white, leave them be.
0
Comment
Question by:phasevar
  • 3
  • 3
7 Comments
 

Expert Comment

by:krisnackaerts
ID: 10926380
Start changing the image to GRAY colorspace, to be sure you have an 8bit image:

convert -colorspace GRAY in.png out.png

then threshold the image to the value you want by

convert -threshold 254 out.png bw.png

This should do the trick
0
 

Author Comment

by:phasevar
ID: 10935329
The first convert produces a grayscale image for me, but the second command's output is a 100% white image and it doesn't matter what I set the threshold to, it turns out as just a plain white image every time.

I tried:

convert -black-threshold 254 out.png bw.png

but that didn't work either, its output looks the same as the input.

I'm using ImageMagick 6.0.0.  
0
 

Expert Comment

by:krisnackaerts
ID: 10935690
I used 5.5.7. It worked. I uninstallled it now, installed 6.0.0 Q16, tried it, didn't work. So it seems a bug in this version. I then double checked it by uninstalling v6.0.0 again, downloading v5.5.7 Q8, and it does work with this version.

My tip: uninstall 6.0.0 and install 5.5.7 for the moment. Try to log the problem. I logged something similar a while ago and the bug was solved in a few days time. You could also try the latest beta to see if they solved it already.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:phasevar
ID: 10956568
I tried both the latest beta, and the 5.5.7 and both of them produced blank (white) images for me.  

I start with what is clearly a grayscale image when loaded in my browser.  Then after the command

convert -threshold 254 out.png bw.png

bw.png is pure white.
0
 

Accepted Solution

by:
krisnackaerts earned 500 total points
ID: 10956586
Next question, which operating system are you using? Windows 95/98/2000/NT/XP, Linux, ...?

It's not because an image shows grayscale, it is grayscale (i.e. 8 bit grayscale). That's why I added the comment above. Also, maybe your white is not exactly white (254), have you tried with v 5.5.7 and other values (e.g. 128 to start with)?

I ask this because it works for me.

Does it need to be imagemagick?
0
 

Author Comment

by:phasevar
ID: 10956638
Linux.

Yes, I tried 5.5.7 with a value of 128 and same result.  Doesn't seem to matter what value I use for threshold, the result is always 100% white.

It doesn't have to be ImageMagick I suppose..  I'm not aware of any other command line utilities for this sort of thing.  My app is in Python and unfortunately I can't find all the tools I need there either.

I don't see why it should matter, but the first step in my process is to pull the matte out of a png image like so:

convert light.png -channel matte light_matte.png

Then I convert with -colorspace GRAY, then onto the convert -threshold.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Color Difference On Site 19 148
mpeg files joining and playing in order 7 184
D3, dragging and rotating. 7 121
svg images disappeared after editing 7 38
Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
Learn how to create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…
Learn how to use the remote presentation tool in Prezi to allow you to harness the power of this cloud based presentation platform. You can show your presentation with a remote audience using this free tool.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now