Reputation: 404
I have picture like this:
It has text stamps randomly distributed throughout the image file. Some aspect to keep in mind about the image are;
So my question is;
Although even if I found the exact location of the text, how do I get rid it? I could try to figure out the random background and do something like I've mentioned as follows;
Upvotes: 0
Views: 1597
Reputation: 359
The following code removes the stamp from your image:
inp_img = cv2.imread('stamp.jpg',cv2.IMREAD_GRAYSCALE)
th,inp_img_thresh = cv2.threshold(255-inp_img,220,255,cv2.THRESH_BINARY)
dilate = cv2.dilate(inp_img_thresh,np.ones((5,5),np.uint8))
canny = cv2.Canny(dilate,0,255)
_,contours,_ =
cv2.findContours(canny,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
test_img = inp_img.copy()
for c in contours:
(x, y, w, h) = cv2.boundingRect(c)
#print(x,y,w,h,test_img[y+h//2,x-w])
test_img[y+3:y-2+h,x+3:x+w] = 240 #test_img[y+h//2,x-w]
cv2.imwrite("stamp_removed.jpg",test_img)
cv2.imshow("input image",inp_img)
cv2.imshow("threshold",inp_img_thresh)
cv2.imshow("output image",test_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Upvotes: 2