ellipse-shaped structuring element for morphology

Pratap Vardhan pratapgr8 at gmail.com
Tue Oct 7 05:48:30 EDT 2014


Updating with plain text


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)


ellipse(3, 3)

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)


ellipse(3, 5)

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)



On Tuesday, October 7, 2014 2:54:48 PM UTC+5:30, Pratap Vardhan wrote:
>
> Here's a ellipse-shaped structuring element for morphology operations
>
> 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?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20141007/9393766f/attachment.html>


More information about the scikit-image mailing list