Search code examples
image-processingscikit-imageopencvpython

Any way to get strongest edge local to a contour line using cv2 or scikit-image?


I am working on accurately segmenting objects from an image.

I have found contour lines by using a simple rectangular prism in HSV space as a color filter (followed by some morphological operations on the resulting mask to clear up noise). I found this approach to be better than applying canny edge detection to the whole image as that just picked up a lot of other edges I don't care about. Is there a way to go about refining the contour line I have extracted such that it clips to the strongest local edge kind of like Adobe Photoshop's smart cropping utility? Here's an image of what I mean

enter image description here

You can see a boundary between the sky blue and the gray. The dark blue is a drawn on contour. I'd like to somehow clip this to the nearby edge. It also looks like there are other lines in the grey region, so I think the algorithm should do some sort of more globalish optimisation to ensure that the "clipping" action doesn't jump randomly between my boundary of interest and the nearby lines.


Solution

  • Here are some ideas to try:

    Based on this comment, the last one is the most useful.