0

I have used Pytesseract and openCV to read text from an image. I used the median blur, normalization and threshold to remove the background and was able to read the text.

However, some parts of the text have turned too light during the process of normalization and I wish to darken them so that they match the darkness/intensity of the remaining text in the image. I tried morphological transformations and tried canny+erosion to remove noise, but neither of those helped.

My input looks like this:

The input

In here, "Code", "Division Name", "15" and "Mechanical" are lighter and I am unable to read them, whereas I am easily able to read "Air Distribution" and "Basic materials & methods".

Any help regarding how to change the color of the lighter text would be greatly helpful.

Graham
  • 7,431
  • 18
  • 59
  • 84
developer
  • 257
  • 1
  • 3
  • 15

1 Answers1

6

You can make change in threshold and then apply erode in the white-text-in-black-ground image.

import cv2
import numpy as np

image = cv2.imread("1.png")

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

blur = cv2.blur(gray,(3,3))

_,thresh = cv2.threshold(blur,240,255,cv2.THRESH_BINARY)
cv2.imshow("thresh",thresh)

thresh = cv2.bitwise_not(thresh)

element = cv2.getStructuringElement(shape=cv2.MORPH_RECT, ksize=(5, 5))

erode = cv2.erode(thresh,element,3)
cv2.imshow("erode",erode)

cv2.imshow("img",image)
cv2.waitKey(0)
cv2.destroyAllWindows()

enter image description here

Ha Bom
  • 2,787
  • 3
  • 15
  • 29
  • Thank you, but I am still unable to detect those lighter parts – developer Jan 16 '19 at 09:24
  • I just show you how to make the lighter parts visible by adjust the threshold. It's hard for me to know what extractly you're doing for the whole thing. – Ha Bom Jan 16 '19 at 09:34
  • Yes I understand. I amusing OCR engine to read text from an image and the attached image is a part of the bigger image. I am just unable to read the lighter parts, even if i darkened it (by taking your solution), Tried removing noise as well, but didn't seem to help – developer Jan 16 '19 at 09:36