Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove wavy noise from image background using OpenCV

Tags:

python

opencv

I would like to remove noise exists in the background. the noise isn't in a standard pattern. I would like to remove the background noise and keep the text on white background.

This an image sample :

enter image description here

I used the below code very simple processing steps.

import cv2 
import numpy as np

img = cv2.imread("noisy.PNG")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.subtract(255,gray)
ret,thresh = cv2.threshold(gray,5,255,cv2.THRESH_TOZERO)


noisy_removal = cv2.fastNlMeansDenoising(thresh, None, 65, 5, 21)
cv2.imwrite("finalresult.jpg",255-noisy_removal)

Here is the output image:

enter image description here

How I can enhance this result

like image 591
ahmed osama Avatar asked Jul 14 '18 21:07

ahmed osama


1 Answers

You can play around with contrast/brightness to remove background pixels as discussed in this post.

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

alpha = 2.5
beta = -0.0

denoised = alpha * gray + beta
denoised = np.clip(denoised, 0, 255).astype(np.uint8)

denoised = cv2.fastNlMeansDenoising(denoised, None, 31, 7, 21)

result

like image 199
zindarod Avatar answered Oct 05 '22 03:10

zindarod