Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actual implementation of the medial axis transform?

I have seen plenty of explanations of what the algorithm is based on, but I can not seem to find any actual code (pseudocode or in some language) of the medial axis transform itself.

For certain instances (such as polygons with discrete corners), it can be simplified into a delaunay triangle, but I am more concerned with the case that you have a blob (such as a human being tracked) and want to compute its skeleton.

What would the pseudocode for this look like?

like image 505
pict Avatar asked Feb 12 '11 14:02

pict


1 Answers

Here you have the code from the pymorph library:

It's basically:

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

Of course it uses another functions from the same package.

An example from Mathematica

enter image description here

HTH!

like image 76
Dr. belisarius Avatar answered Sep 25 '22 00:09

Dr. belisarius