Search code examples
pythonimage-processingcontour

Finding contour around a cluster of pixels


I have a set of images that look like this:

enter image description here

Using python need a way to find a contour around the yellow shape that ignores the isolated points and is not too complex. Something looking a bit like this :

enter image description here

I tried some methods such as the find_contours function from skimage,which gives this after keeping only the biggest contour:

enter image description here

which is not what I am looking for. A also tried active contour (snake) which had the problem of paying too much attention to isolated pixels. Is there a particular method that would help me in this situation ?

Thank you


Solution

  • Assuming the yellow blob is slightly different across your images, I recommend you look into either using Morphological Operations, or using Contour Approximation.

    I've never used scikit-image, but it appears to have Morphological functionalities included. You can take a look at this OpenCV tutorial for a quick guideline of the different operations. But I think all you need is to use the "Opening" operation to preprocess your yellow shape; making it smoother and removing the random speckles.

    Another approach is by approximating that contour you've extracted to make it smoother. For scikit-image, that is the measure.approximate_polygon function. Also another OpenCV tutorial for reference on how Contour Approximation works (the same algorithm as with scikit-image).