Ask Your Question

frank ruethrich's profile - activity

2013-05-02 07:49:02 -0600 received badge  Editor (source)
2013-05-02 07:46:03 -0600 answered a question I need a maxEnclosingCircle function

Seiko,

unless you posted this question some months ago I still stumbled into the same unanswered question. My answer would be: Why don't you simply

  1. do a distance transform (in python for example using ndimage.distance_transform_edt explained here some way down the page)

  2. take the point with the largest distance as center and

  3. take the corresponding distance as the radius?

The result should be a fastly computed maximum enclosed circle for all types of polygons. Or am I wrong somehow? Greets, Frank

#   +++calculate maximum enclosed circle+++

def maxEnclosedCircle(binent): 
# binent is an array where the shape of interest has a value larger than 0

    #distance transform
    dist = ndimage.distance_transform_edt(binent>0)

    #set radius to largest distance

    radius=np.amax(dist)

    #get index
    flatind=np.argmax(dist)#index of flattened arrays
    ind=np.unravel(flatind,dist.size)#convert to 2D index

    #check if multiple maxima exist and how many
    a=len(dist[dist==radius])

    return ind,radius,a