Page 1 of 1

Process an image for better OCR, returns a black one...

Posted: 2017-03-23T05:25:08-07:00
by geko
Hello all!

I am using this code to improve an image and help the OCR process. Problem is for some reason, final image is always black.

Code: Select all

QuantizeSettings qs = new QuantizeSettings();
qs.ColorSpace = ColorSpace.Gray;
image.Quantize(qs);
image.ColorType = ColorType.Grayscale;
image.ContrastStretch(new Percentage(0), new Percentage(0));

QuantizeSettings qs2 = new QuantizeSettings();
MagickImage img2 = image.Clone();
qs2.ColorSpace = ColorSpace.Gray;
img2.Quantize(qs2);
img2.Negate();
img2.AdaptiveThreshold(15, 15, 10);
img2.ContrastStretch(new Percentage(0), new Percentage(0));

image.Composite(img2, CompositeOperator.CopyAlpha);
image.Opaque(new MagickColor(System.Drawing.Color.White), new MagickColor(System.Drawing.Color.White));
image.Alpha(AlphaOption.Activate);
image.Deskew(new Percentage(40));
image.Sharpen(Channels.Black);
What am i doing wrong?

P.S.
Actually, i am trying to implement this:
http://www.fmwconcepts.com/imagemagick/ ... /index.php

Thanks!

Re: Process an image for better OCR, returns a black one...

Posted: 2017-03-23T05:30:05-07:00
by dlemstra
You don't need to create that yourself. You can download a NuGet package with that script here: https://www.nuget.org/packages/FredsIma ... xtCleaner/. Be aware that you need to pay a small fee if you want to use it in a commercial project.