I'm trying to remove a noise from a photo of a monitor screen. Here's the source photo:
I've tried some different approaches, so the current version of my code is as follows:
clr_img = cv2.imread("D:\Noisy.jpg", 1)
gray_img = cv2.cvtColor(clr_img, cv2.COLOR_BGR2GRAY)
gray_img = cv2.fastNlMeansDenoising(gray_img, h=11)
binary_image = cv2.adaptiveThreshold(gray_img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 91, 12)
Here's the result:
Is it possible to get rid of this kind of the noise?
You need to apply a smoothing operation before adaptive thresholding. A simple blur should help to reduce the noise. Any of these should work: Simple average blur (cv2.blur
), Gaussian blur (cv2.GaussianBlur
), or Median blur (cv2.medianBlur
). Here's the result using a (7,7)
Gaussian blur:
import cv2
image = cv2.imread('1.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (7,7), 0)
thresh = cv2.adaptiveThreshold(blur,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV,51,9)
result = 255 - thresh
cv2.imshow('thresh', thresh)
cv2.imshow('result', result)
cv2.waitKey()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With