Ask Your Question

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

asked 2015-07-15 13:51:17 -0500

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-07-16 10:55:06 -0500

LBerger gravatar image

updated 2015-07-16 13:52:24 -0500

You must see your structuring element as a distance. All element which belong to structurinf element are at "same distance" from center. So when structuring element is square distance is like norm-Linfini. when structuring element is a disk distance is like norm-L2

edit flag offensive delete link more



I can kind of see what you are saying. (although I think you're wrong about the square -- a square aligned with the x axis is like norm-inf, a square rotated 45 degrees and inscribed in the larger square is like norm-L1).

But in any case, what effects would this consideration of distance have on the image? And why might someone use another shape like a cross or a rectangle?

benkuykendall gravatar imagebenkuykendall ( 2015-07-16 12:09:43 -0500 )edit

you're right about square L1 and L-inf.

About shape I think its ddepends what you want to do I prefer a disk when I need unit on my image like surface in microscopy.. A small square can be used to feel hole in a contour

LBerger gravatar imageLBerger ( 2015-07-16 13:52:05 -0500 )edit

Question Tools

1 follower


Asked: 2015-07-15 13:51:17 -0500

Seen: 637 times

Last updated: Jul 16 '15