Create Structuring Element for Image Morphology Python

1.9k views Asked by At

I am working with morphological operations.I have a Matlab script which generate the Structuring Element using the function strel('form', w) where the form of the SE can be a line, disk, diamond, square, or other form (I need at least the function to be able to generate this 4 forms), and w is the size of the matrix (w*w) generated for the SE. I want to know if there is a function in Python similar to Matlab "strel()" that automatically generates the Structuring Element. I´ve search for this kind of function, but none of them seems to be able to generate all this 4 different Structuring Element forms.

2

There are 2 answers

0
mimocha On

Unfortunately the built-in OpenCV functions appear to provide only rectangles, ellipses, and crosses. So you'll have to write your own function for that.

Alternatively, you could try to get MATLAB and python to interact with each other, and call MATLAB from python. Refer to the various documentation pages on how to do this:

0
Cris Luengo On

Scikit-image has functions to generate square, rectangle, disk, diamond, octagon and star shaped structuring elements.

They are separate functions, not a single function, but I can’t imagine that being a problem.

Call them as skimage.morphology.<shape>(). See this documentation page for demos.

Horizontal and vertical lines are rectangle shapes, of course. Lines at arbitrary angles can be generated by drawing a line in an all-zeros array with skimage.draw.line.