I have two images that I will like to combine together and fill/remove the gaps between the borders after combining. The image on the left is the edge while the image on the right is the mask. (Ignore the little patch on the right picture but it will be nice to be able to remove it too)
The expected result after combination is
but this is the current result achieved so far
I have tried different strategies from scikit-image apis, which includes:
ndi.binary_opening
, ndi.binary_closing
, morphology.{erosion, dilation, opening, closing}
but none of them seem to work.
I think this may be a basis for a strategy...
Step 1:
Start with the "edge image". Randomly choose any white pixel. Flood fill with black using that pixel as the seed, or start point. This should fill one side of the edge. Remember the seed, and get centroid (and maybe area) of the new, filled in black area. Invert the filled-in image and get the centroid of the other part of the image.
You now know the centroids of both sides of the edge - as marked in red below:
Step 2:
Now move to the mask image. Maybe use dilation/erosion to fill in any smallish holes. Then run "labelling" on the image to get a list of the contiguous black blobs and their centroids and areas. Select the largest blob by area.
You should now have the centroid of the largest blob as marked in green below:
Step 3:
Now choose the nearer of the two red points to the green one and use the corresponding seed to do your fill.
It may better at Step 1 to repeatedly choose white seed points at random till you get a different centroid, rather than doing the inversion. That's because if you just invert and get the centroid, you don't know a good seed pixel. It's not certain that the centroid a good seed.