[mmopenth] [Up] [mmskelmrec] Residues

mmskelm
Morphological skeleton (Medial Axis Transform).

Synopsis

y = mmskelm( f, B = None, option = "binary" )

Implemented in Python.

Input

f Image Binary image.
B Structuring Element

Default: None (3x3 elementary cross)

option String

Choose one of: binary: output a binary image (medial axis); value: output a grayscale image with values of the radius of the disk to reconstruct the original image (medial axis transform).

Default: "binary"

Output

y Image Gray-scale (uint8 or uint16) or binary image.

Description

mmskelm creates the image y by computing the morphological skeleton by B of the image f, when option is BINARY. In this case, the pixels of value 1 in y are center of maximal balls (generated from B) included in f. This is also called Medial Axis. If option is VALUE, the non zeros pixels in y are the radius plus 1 of the maximal balls. This is called Medial Axis Transform or valued morphological skeleton.

Examples

>>> from Numeric import ones

              
>>> a=mmneg(mmframe(mmbinary(ones((7,9)))))

              
>>> print a
[[0 0 0 0 0 0 0 0 0]
 [0 1 1 1 1 1 1 1 0]
 [0 1 1 1 1 1 1 1 0]
 [0 1 1 1 1 1 1 1 0]
 [0 1 1 1 1 1 1 1 0]
 [0 1 1 1 1 1 1 1 0]
 [0 0 0 0 0 0 0 0 0]]
>>> print mmskelm(a)
[[0 0 0 0 0 0 0 0 0]
 [0 1 0 0 0 0 0 1 0]
 [0 0 1 0 0 0 1 0 0]
 [0 0 0 1 1 1 0 0 0]
 [0 0 1 0 0 0 1 0 0]
 [0 1 0 0 0 0 0 1 0]
 [0 0 0 0 0 0 0 0 0]]
>>> print mmskelm(a,mmsebox())
[[0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0]
 [0 0 0 1 1 1 0 0 0]
 [0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0]]
>>> a=mmreadgray('pcbholes.tif')

              
>>> b=mmskelm(a)

              
>>> mmshow(a)

              
>>> mmshow(b)

            
a b
>>> c=mmskelm(a,mmsecross(),'value')

              
>>> mmshow(c)

            
c

Equation

Source Code

def mmskelm(f, B=None, option="binary"):
    from string import upper
    from Numeric import asarray
    if B is None: B = mmsecross()
    assert mmisbinary(f),'Input binary image only'
    option = upper(option)
    k1,k2 = mmlimits(f)
    y = mmgray(mmintersec(f, k1),'uint16')
    iszero = asarray(y)
    nb = mmsesum(B,0)
    for r in range(1,65535):
        ero = mmero( f, nb)
        if mmisequal(ero, iszero): break
        f1 = mmopenth( ero, B)
        nb = mmsedil(nb, B)
        y = mmunion(y, mmgray(f1,'uint16',r))
    if option == 'BINARY':
        y = mmbinary(y)
    return y
    

See also

mmfreedom Control automatic data type conversion.
mmcbisector N-Conditional bisector.
mmthin Image transformation by thinning.
mmskelmrec Morphological skeleton reconstruction (Inverse Medial Axis Transform).
[mmopenth] [Up] [mmskelmrec] Python