MathanKumar
MathanKumar

Reputation: 623

In pytyon is it possible to prevent the text's pixel while removing lines in image?

I'm working in text extraction process inside the table.But while removing the table lines it affecting the text's pixel.is is possible to keep the text pixel which is overlays on the table line pixel.

original image as RGB enter image description here

this image is the cropped from original image for reference

output region enter image description here

Upvotes: 0

Views: 64

Answers (1)

Alex Alex
Alex Alex

Reputation: 2018

Use eroded (or dilated black objects) second image as mask for first image.

import cv2
import numpy as np
#images need equal size
original=cv2.imread('RdfpD.png')
mask = cv2.imread('zxLX4.png', cv2.IMREAD_GRAYSCALE)
se=cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,5))
ret,thresh = cv2.threshold(mask,60,255,cv2.THRESH_BINARY_INV)

dilate = cv2.dilate(thresh,se,iterations = 1)
dilate=cv2.bitwise_not(dilate)
dilate=cv2.cvtColor(dilate, cv2.COLOR_GRAY2BGR)
out=cv2.max(dilate, original)
cv2.imwrite('out_5.png', out)

enter image description here

Upvotes: 1

Related Questions