Improve image quality using Emgu.CV

Viewed 182

I am trying to read text from images using Tesseract. As the image quality is not good I'm using image processing before tesseract-ocr to improve the accuracy.

Image link: https://i.stack.imgur.com/ZaA8M.jpg

Wrote below code to detect edges by using a Gaussian filter:

var img = new Image<Gray, Byte>("ZaA8M.jpg");
Image<Gray, byte> Img_Source_Gray = img.Copy();
Image<Gray, byte> Img_Egde_Gray = Img_Source_Gray.CopyBlank();
Image<Gray, byte> Img_SourceSmoothed_Gray = Img_Source_Gray.CopyBlank();
Image<Gray, byte> Img_Otsu_Gray = img.CopyBlank();

//Smooth the edges by using a Gaussian filter
Img_SourceSmoothed_Gray = Img_Source_Gray.SmoothGaussian(3);

//Segmentation of the characters by using a threshold
CvInvoke.Threshold(Img_Source_Gray, Img_Otsu_Gray, 255, 0, Emgu.CV.CvEnum.ThresholdType.Otsu | Emgu.CV.CvEnum.ThresholdType.Binary);

Bitmap imgb = (Bitmap)byteArrayToImage(Img_Otsu_Gray.ToJpegData());
imgb.Save("test.jpg");

Output image link: https://i.stack.imgur.com/Bj8XX.jpg

After applying the threshold, characters become more dark black color and not it's readable.

How to improve the above image quality to read the text from it using tesseract-ocr?

1 Answers

I think you are doing to much image processing. For example your original image already has letters that are touching each other. By applying a SmoothGaussian filter, you are likely making those edges blend even more into each other, although you are smoothing out some irregularities at other spots. Also I prefer working with png images instead of jpg when the input is low quality, because the jpg compression adds another layer of quality loss.

I did a single filter on your image with well chosen parameters (vb.net)

img.ThresholdAdaptive(New Gray(255), CvEnum.AdaptiveThresholdType.GaussianC, CvEnum.ThresholdType.Binary, 45, New Gray(9))

and this is my image result

image after adaptive filter

here is my Tesseract result

Supplement Facts
Serving Size 30 Drops (1 ml)
Servings Per Container 30

Amount Per Serving 333mg
Herb Weight Equivalence

Organic
Milk Thistle Seed
(Silybum marianum)

Herb Strength Ratio 1:3

* Daily Value Not Established

OTHER INGREDIENTS: :
ionized Water, Grain Alcohol
(20-30% by volume) |

— 4

using this as tesseract v5.0.0 command line

tesseract.exe --oem 3 --psm 3 -l eng "c:\temp\input.png" "C:\temp\output"
Related