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

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
geko
Posts: 1
Joined: 2017-03-23T05:14:38-07:00
Authentication code: 1151

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

Post 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!
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

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

Post 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.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Post Reply