I have an image that I am trying to process:

enter image description here

I want two seamingly contradictory effects:

  1. I want to remove "holes" inside "the blob". That is I want all pixels inside the blob to be solid red.

  2. I want to move the boundary of the blob inwards.

From what I gather the morphological operation dilatation would do 1. and erosion would do 2?

But dilatation and erosion counteract each other?

How would you suggest I go about to achieve the desired result?


1 Answer 1


You will want to use the morphological closing operation, which is the erosion of the dilation of an image. This means that you first dilate the image, removing the small 'holes' in the interior of the image, and then you erode the image, shrinking the boundary. If you want the final boundary to be 'smaller' than the original boundary, simply erode more than you dilate, ensuring that you dilate enough to completely fill the interior holes first.

The idea behind this is that by removing the holes via dilation, the information about those holes is lost from the image. When you then proceed to erode the image, there are no longer interior gaps to erode away from, so it only erodes away from the outer image. Therefore, despite being opposing operations, the erosion does not simply reverse the dilation, provided the feature sizes to be removed are 'smaller' than the size of the dilation.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.