0

I am performing adaptive thresholding on an image to find an object's borders. However, on some points of the object, the adaptive threshold has gaps and spills over into other objects (due to colour similarity in rare points on the object's border). These gaps are too large to fill in using morphological closing (dilate followed by erosion).

Is there a way to detect these and remove them, considering they don't occur very often, and are relatively small to the perimeter of the entire shape.

I've found that just increasing iterations/window sizes for closing just messes up things too much to be useful.

I want to perform houghline transform after a good adaptive threshold, but the adaptive threshold spilling out of the object of interest's boundaries add many more potential line detections into the binary image.

I thought maybe running kernels over the detected lines in those images and adding white pixels if sufficiently small breaks are detected in the adaptive threshold borders? Has anyone tried something like this?

Thanks!

Example gap in threshold before morph close

Example gap in threshold before morph close

Example gap in threshold after morph close

Example gap in threshold after morph close

mosfeta
  • 1
  • 1
  • 1
    Try filtering your blobs/contours by size. Set an area threshold and everything below that area (the noisy blobs, in this case) will get filtered. Check out this answer: https://stackoverflow.com/questions/59863948/clean-text-images-with-opencv-for-ocr-reading/59870275#59870275 – stateMachine Sep 23 '20 at 07:40
  • If you have more or less straight lines, have a look at OpenCV's [Hough Line Transform](https://docs.opencv.org/4.4.0/d9/db0/tutorial_hough_lines.html). – HansHirse Sep 23 '20 at 07:46
  • @eldesgraciado That is a cool technique thanks! But unfortunately this also removes even more of the object boundary shown in the first image, making it harder to salvage the entire object boundary – mosfeta Sep 24 '20 at 01:22
  • @HansHirse I do intend to do hough transform after I find a good closed object boundary, but if the boundary isn't closed, it spills over into the rest of the image and adds many potential hough line detections. – mosfeta Sep 24 '20 at 01:25
  • @mosfeta Perform your area filtering _after_ your morphological operations. For example, try it after the closing operation. – stateMachine Sep 24 '20 at 02:14

0 Answers0