Converting(any?) image to black and white

Mar 4, 2014 at 9:05 PM
Edited Mar 4, 2014 at 9:10 PM
First off, very cool library, thank you for creating it. Also, my questions are probably more related to my lack of image understanding than the library but anyway.

I have a JPG file(which I hope uploading to photobucket did not change.
[Image]
http://i1333.photobucket.com/albums/w623/rangothonlinerangoth/photo_zps3b2313f9.jpg
[/Image]

and I am trying to convert it to a pure B&W 1 bit image, using either dithering, thresholding, etc.

When I convert it to a TIFF and use GROUP 4 compression I do seem to be able to get the image to turn B&W and I've been able to successfully convert it to TIFF, open and view it in other application etc.

But I cannot seem to save it as a JPG(original format) that is 1bit B&W.

I've tried all sorts of crazy combinations of the following mutators/function calls:
.BlackThreshold()
.BitDepth(Channels.All, 1)
.Depth = 1

I've also tried a .Strip() before those calls based on some other responses I saw about certain profiles overriding things(not sure if I fully understand that part).

The only thing that seems to work is this:
                    this.imageData[page].QuantizeColorSpace = ColorSpace.GRAY;
                    this.imageData[page].QuantizeDither = true;
                    this.imageData[page].Quantize();
But it turns it gray, not B&W

I hope this doesn't come across at nit-picky, just curious on how to achieve what I am looking for if it is even possible.

Side question: is there any documentation on what the actual function calls do? Like an MSDN/API doc?

-Mark
Coordinator
Mar 5, 2014 at 5:21 AM
Edited Mar 8, 2014 at 7:43 PM
The .Strip method does not influence the value of a pixel. It removes metadata from an image file (http://www.imagemagick.org/script/command-line-options.php#strip).

You should be able to do the following (this is the equivalent of convert.exe photo_zps3b2313f9.jpg -threshold 25% blackwhite.jpg):
using (MagickImage image = new MagickImage(@"photo_zps3b2313f9.jpg"))
{
  image.Threshold(25);
  image.Write("blackwhite.jpg");
}
But this does not seem to work and creates a completely white image. I will have to investigate this for you to figure out what is happening.

If you are looking for documentation about what actual function calls do I would advise you to visit: http://www.imagemagick.org/Usage/ or check the command line options on this page: http://www.imagemagick.org/script/command-line-options.php. The names of the command line options are almost the same as the methods in the MagickImage class.
Mar 5, 2014 at 4:10 PM
Thank you very much for the response. I appreciate the link as well. I somehow missed that in all of my searching.

-Mark
Coordinator
Mar 8, 2014 at 7:45 PM
That link can be found on the bottom of the documentation page. I have made this more clear so it won't be that easy to miss it anymore.

The problem with Threshold will be fixed in the next release of Magick.NET. It will use a percentage instead. You can find an example in this topic: https://magick.codeplex.com/discussions/538324.