Here's a ellipse-shaped structuring element for morphology operations
In [131]:
def ellipse(w, h, dtype=np.uint8):
""" Generates a flat, ellipse-shaped structuring element.
Parameters
----------
w : int
The width of ellipse
h : int
The height of ellipse
Other Parameters
----------------
dtype : data-type
The data type of the structuring element.
Returns
-------
selem : ndarray
A structuring element consisting only of ones, i.e. every
pixel belongs to the neighborhood.
"""
X, Y = np.meshgrid(range(-w, w + 1), range(-h, h + 1))
return np.array(((h*X) ** 2 + (w*Y) ** 2) <= (w*h) ** 2,
dtype=np.uint8)
In [129]:
ellipse(3, 3)
Out[129]:
array([[0, 0, 0, 1, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 1, 0, 0, 0]], dtype=uint8)
In [130]:
ellipse(5, 3)
Out[130]:
array([[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]], dtype=uint8)
Can this be taken as it is or certain approximation formulas need to be
used? Any alternative way skimage uses as of now? If not, can this go as a
PR?