# mmsedisk
Create a disk or a semi-sphere structuring element.

## Synopsis

B = mmsedisk( r = 3, DIM = "2D", METRIC = "EUCLIDEAN", FLAT = "FLAT", h = 0 )

Implemented in Python.

### Input

r | Double Non-negative integer. Disk radius. Default: `3`
DIM | String '1D', '2D, or '3D'. Default: `"2D"`
METRIC | String 'EUCLIDEAN', ' CITY-BLOCK', 'OCTAGON', or ' CHESSBOARD'. Default: `"EUCLIDEAN"`
FLAT | String 'FLAT' or 'NON-FLAT'. Default: `"FLAT"`
h | Double Elevation of the center of the semi-sphere. Default: `0`

### Output

B | Structuring Element

## Description

mmsedisk creates a flat structuring element `B` that is disk under the metric METRIC , centered at the origin and with radius `r` or a non-flat structuring element that is a semi-sphere under the metric METRIC, centered at `(0, h)` and with radius `r`. This structuring element can be created on the 1D, 2D or 3D space.

## Examples

Examples of flat structuring elements.

    >>> a=mmseshow(mmsedisk(10,'2D','CITY-BLOCK'))

    >>> b=mmseshow(mmsedisk(10,'2D','EUCLIDEAN'))

    >>> c=mmseshow(mmsedisk(10,'2D','OCTAGON'))

    >>> mmshow(a)

    >>> mmshow(b)

    >>> mmshow(c)

a | b | c |

Examples of non flat structuring elements.

    >>> d=mmseshow(mmsedisk(10,'2D','CITY-BLOCK','NON-FLAT'))

    >>> e=mmseshow(mmsedisk(10,'2D','EUCLIDEAN','NON-FLAT'))

    >>> f=mmseshow(mmsedisk(10,'2D','OCTAGON','NON-FLAT'))

    >>> mmshow(d)

    Warning: Converting input image from int32 to uint16.

    >>> mmshow(e)

    Warning: Converting input image from int32 to uint16.

    >>> mmshow(f)

    Warning: Converting input image from int32 to uint16.

d | e | f |

    >>> g=mmsedisk(3,'2D','EUCLIDEAN','NON-FLAT')

    >>> mmseshow(g)

    array([[-2147483647, -2147483647,           1,           1,           1, -2147483647,
                 -2147483647],
           [-2147483647,           2,           2,           2,           2,           2,
                 -2147483647],
           [          1,           2,           3,           3,           3,           2,
                           1],
           [          1,           2,           3,           3,           3,           2,
                           1],
           [          1,           2,           3,           3,           3,           2,
                           1],
           [-2147483647,           2,           2,           2,           2,           2,
                 -2147483647],
           [-2147483647, -2147483647,           1,           1,           1, -2147483647,
                 -2147483647]],'i')

    >>> h=mmsedisk(3,'2D','EUCLIDEAN','NON-FLAT',5)

    >>> mmseshow(h)

    array([[-2147483647, -2147483647,           6,           6,           6, -2147483647,
                 -2147483647],
           [-2147483647,           7,           7,           7,           7,           7,
                 -2147483647],
           [          6,           7,           8,           8,           8,           7,
                           6],
           [          6,           7,           8,           8,           8,           7,
                           6],
           [          6,           7,           8,           8,           8,           7,
                           6],
           [-2147483647,           7,           7,           7,           7,           7,
                 -2147483647],
           [-2147483647, -2147483647,           6,           6,           6, -2147483647,
                 -2147483647]],'i')

## Equation

Flat structuring element:
Euclidean distance:
City block distance (4-connectivity):
Chess board distance (8-connectivity):
Octagon distance:
Non-flat structuring element:
Euclidean distance:
city block distance:
chess board distance:

## Source Code

    def mmsedisk(r=3, DIM="2D", METRIC="EUCLIDEAN", FLAT="FLAT", h=0):
        from string import upper
        from Numeric import resize, transpose, arange
        from Numeric import sqrt, arange, transpose, maximum
        METRIC = upper(METRIC)
        FLAT   = upper(FLAT)
        assert DIM=='2D','Supports only 2D structuring elements'
        if FLAT=='FLAT': y = mmbinary([1])
        else:            y = int32([h])
        if r==0: return y
        if METRIC == 'CITY-BLOCK':
            if FLAT == 'FLAT':
                b = mmsecross(1)
            else:
                b = int32([[-2147483647, 0,-2147483647],
                           [          0, 1,          0],
                           [-2147483647, 0,-2147483647]])
            return mmsedil(y,mmsesum(b,r))
        elif METRIC == 'CHESSBOARD':
            if FLAT == 'FLAT':
                b = mmsebox(1)
            else:
                b = int32([[1,1,1],
                           [1,1,1],
                           [1,1,1]])
            return mmsedil(y,mmsesum(b,r))
        elif METRIC == 'OCTAGON':
            if FLAT == 'FLAT':
                b1,b2 = mmsebox(1),mmsecross(1)
            else:
                b1 = int32([[1,1,1],[1,1,1],[1,1,1]])
                b2 = int32([[-2147483647, 0,-2147483647],
                            [          0, 1,          0],
                            [-2147483647, 0,-2147483647]])
            if r==1: return b1
            else:    return mmsedil( mmsedil(y,mmsesum(b1,r/2)) ,mmsesum(b2,(r+1)/2))
        elif METRIC == 'EUCLIDEAN':
            v = arange(-r,r+1)
            x = resize(v, (len(v), len(v)))
            y = transpose(x)
            Be = mmbinary(sqrt(x*x + y*y) <= (r+0.5))
            if FLAT=='FLAT':
                return Be
            be = h + int32( sqrt( maximum((r+0.5)*(r+0.5) - (x*x) - (y*y),0)))
            be = mmintersec(mmgray(Be,'int32'),be)
            return be
        else:
            assert 0,'Non valid metric'
        return B

## See also

mmfreedom | Control automatic data type conversion.
mmsebox | Create a box structuring element.
mmsecross | Diamond structuring element and elementary 3x3 cross.
mmseline | Create a line structuring element.
mmimg2se | Create a structuring element from a pair of images.
mmseshow | Display a structuring element as an image.
mmdil | Dilate an image by a structuring element.

[`mmsecross`] [Up] [`mmseline`] |
Copyright (c) 2003, Roberto A. Lotufo, UNICAMP-University of Campinas; Rubens C. Machado, CenPRA-Renato Archer Research Center.