0

I have these images: enter image description here

I want to remove the noise from the background(i.e make the background white in 1st and 3rd and black in 2nd) in all these images, I tried this method: Remove noise from threshold image opencv python but it didn't work, how can I do it?

P.S This is the original image that I am trying to enhance. enter image description here

WinterSoldier
  • 393
  • 4
  • 15
  • 1
    You can try cleaning it up using erosion and dilation if you haven't done that yet – M Z Aug 03 '20 at 14:36
  • Your question is not very clear. You show noisy images, but then you show your original image, which is already clean. Which images do you want to process - the 3 noisy ones or the 1 good one? – fmw42 Aug 03 '20 at 18:34
  • @fmw42 Actually I want to enhance the original image... i.e the handwriting should become dark(er) and the background pure white... I am doing this to train my ML model – WinterSoldier Aug 03 '20 at 18:43
  • Just use cv2.adaptiveThreshold on that image – fmw42 Aug 03 '20 at 19:52

1 Answers1

5

You can use adaptive threshold on your original image in Python/OpenCV

Input:

enter image description here

import cv2
import numpy as np

# read image
img = cv2.imread("writing.jpg")

# convert img to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# do adaptive threshold on gray image
thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 21, 10)

# write results to disk
cv2.imwrite("writing_thresh.jpg", thresh)

# display it
cv2.imshow("thresh", thresh)
cv2.waitKey(0)
cv2.destroyAllWindows()

Result:

enter image description here

WinterSoldier
  • 393
  • 4
  • 15
fmw42
  • 46,825
  • 10
  • 62
  • 80