简体   繁体   中英

removing black dots from image using OpenCV and Python

I am trying to compare two images and need to pre-process/clean one of them which is a scanned copy before comparing with a digital copy. Scanned copy / Digital copy

I ran this code on the scanned image and got an output which has numerous black dots. Not sure how to clean these up so that I can compare with the digital copy

img = cv2.multiply(img, 1.2)
kernel = np.ones((1, 1), np.uint8)
img = cv2.erode(img, kernel, iterations=1)
kernel1 = np.zeros( (9,9), np.float32)
kernel1[4,4] = 2.0
boxFilter = np.ones( (9,9), np.float32) / 81.0
kernel1 = kernel1 - boxFilter
img = cv2.filter2D(img, -1, kernel1)

below is the output I got

输出图像

Try apply filter in frequency domain, your image after FFT will have regular bright dots, because your image noise. If you will remove these dots and make inverse FFT transform you will remove dots from your image. Check this examples please: example1 , example2 and example3 .

Yes. @Andrey method is the right way of solving the problem. I have tried removing the high frequency dots in the frequency domain and here is an example of how it will look like if done correctly

Original Image in grayscale.

在此处输入图片说明

After running FFT on the image

在此处输入图片说明

Removing all high frequency noise. Of course this is done manually by drawing a black circle around the noise source. You can design your program to detect local bright spot and remove them cleanly.

在此处输入图片说明

Here is the final result after inverse FFT of the above frequency image. Some what degraded due to the crude way of me removing the noise but it should give you a rough idea of how it can be done.

在此处输入图片说明

Only the area around the dots will be affected by this process, leaving all other pattern in their original form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM