Ask Your Question

Revision history [back]

How should I choose the shape of the structuring element for a morphological closing?

I am working on a Python script to identify objects in an image and place each on a transparent background.

My currently steps are

  1. Open image
  2. Apply bilateral filter to smooth textures
  3. Use Canny to find edges
  4. Apply a closing to fill gaps in the edges
  5. Find contours
  6. Use each contour to mask the image appropriately

Everything is working fairly well, but I had a question about the closing.

I am currently using a 5 by 5 square as the structuring element for closing. I am aware of the getStructuringElement method that allows for easy production of other shapes, but I don't understand why I would choose one shape over another. What shapes might I consider for my application, and why?