0

I have a medial axis (computed by skimage.morphology.medial_axis) enter image description here however, there are many tiny branchs which I don't want, so I decide to apply scale axis transform.

I try to compute scale axis transform based on my understanding on scale axis transform:

def disc_contained(disc1, disc2, scale=1.05):
    (p1, r1) = disc1
    (p2, r2) = disc2
    if np.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) + scale * r1 <= scale * r2:
        # disc1 is contained in disc2
        return True
    else:
        return False

skel, distance = medial_axis(bi, return_distance=True)
cv2.imwrite('medial_axis.png', skel * 255)
pos = []
for x, y in np.ndindex((H, W)):
    if distance[x, y] > 0:
        pos.append([x, y])
for i, p1 in enumerate(pos):
    for j, p2 in enumerate(pos):
        if i != j:
            if disc_contained((p1, distance[p1[0], p1[1]]), (p2, distance[p2[0], p2[1]])):
                skel[p1[0], p1[1]] = 0
                break
cv2.imwrite('medial_axis2.png', skel * 255)

however, I find that after scale axis transform the result is lack of the topological connectivity. Below are my results: medial_axis.png enter image description here medial_axis2.png enter image description here

How can I fix it?

Hao Huang
  • 21
  • 2

0 Answers0