I have a sequence of images in which I detect blobs. After some operations, I am able to remove noise and smooth the contours a little, which gives me this kind of results :
Now I have an algorithm that tells me which blobs are supposed to be merged together (because they really belong to the same object), and I want to merge those ones!
I know that there are many solutions to achieve this. But my goal is to find a merging contour that fits the two others quite well ! Which is why a convex hull is not acceptable, it would add too many bias to following calculations (especially the area).
As you can see on the picture, we human would know how to merge them, because it is just an object divided into two, and I wanted to find a contour which keeps the shape of the object.
I tried some solutions but they don't work perfectly, for example :
- convexHull : I was thinking of finding the convex hull of the whole object and then reduce it by adding extra points where the convexity defect is too large, but the function convexityDefects behaves randomly with disjoint contours :
(well, not randomly, it's just the hole which is problematic)
- approxPolyDP : same problem here, with disjoint contours, the function does not behave as I want.
- concave hull : another thing I tried was to compute a concave hull based on this link : ' blog.thehumangeo.com/2014/05/12/drawing-boundaries-in-python/ ' The problem is that I only have the pixels from the external contour to represent my objects ; it turns out it is not enough to compute a good concave hull. And if I retrieve all the pixels inside the contour, then the hull is perfect but the time is too long...
So do you know if there are some functions, algorithms, that can merge close contours while keeping the main shape they represent ?
Thank you in advance.

