0

I have the following code and when I try to perform closing on the threshold image, it looks worse and doesn't remove the pepper noise.

What is the output of an adaptive threshold? and how can I convert this back into a usable format so that closing can be applied?

Or how would you remove the pepper and maybe improve the edges?

import cv2
import numpy as np

#import image
img = cv2.imread('Highway.jpg',0)

#actually finds the edges nicely
thresh = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
            cv2.THRESH_BINARY,11,2)

#closing is not removing the pepper look
#kernel = np.ones((5,5),np.uint8)
#closing = cv2.morphologyEx(th3, cv2.MORPH_CLOSE, kernel)

Highway.jpg

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
  • 1
    Pepper noise can be removed using `cv2.medianBlur()` – Jeru Luke Jan 09 '17 at 19:55
  • Did you go through [THIS DOCUMENTATION](https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_thresholding/py_thresholding.html#thresholding) ? It has sufficient info on thresholding operations. – Jeru Luke Jan 09 '17 at 19:58
  • Yes, many times. even when I set the kernel to 3,3 or even "None" it still does not reduce the pepper noise. I find that "ADAPTIVE_THRESH_GAUSSIAN_C" delivers the clearest lines. you would think that a simple closing would reduce the pepper noise then you can apply a cv2.Canny to further define the edges. I have also been trying the watershed algorithm but haven't been able to make it work. My goal here is to outline each lane. – Exclusiveicon Jan 09 '17 at 20:21
  • Threshold is all I can think of. I will work on it if I have time. In the mean time look for some other sources as well – Jeru Luke Jan 09 '17 at 20:24

0 Answers0