This project has moved and is read-only. For the latest updates, please go here.

Binarizing an image with magick.net

Feb 1 at 9:53 PM
Edited Feb 2 at 5:10 PM
I'm having trouble figuring out how to binarize an image for OCR with magick.net
Im currently converting the image to greyscale and then normalizing but im not sure how to convert the colors to black and white in between
MagickImage x = new MagickImage(originalImage);
x.ColorSpace = ImageMagick.ColorSpace.Gray;
// This is where im missing a step
x.Normalize();

The options in image magick that im trying to replicate are
-colorspace gray +dither -colors 2 -normalize
Feb 3 at 8:39 AM
Edited Feb 3 at 8:46 AM
The -colors option has a completely different name in the MagickImage class. It will call the quantize method. Your command translates to this:
image.Quantize(new QuantizeSettings()
{
  ColorSpace = ColorSpace.Gray, // -colorspace gray
  DitherMethod = DitherMethod.No, // +dither
  Colors = 2 // -colors 2
});
image.Normalize(); // -normalize