如何提高 medial_axis 制作的骨架质量

how to improve quality of skeleton made with medial_axis

我正在尝试使用 medial_axis 制作图像骨架,但由于某种原因,结果非常混乱

有谁知道我该如何改进它?

我也尝试过使用 skeletonize,骨架本身看起来更好,但它并不是我想要的。

import matplotlib.pyplot as plt
from skimage.io import imread
from skimage.filters import threshold_otsu
from skimage.morphology import medial_axis

def Get_binary(image):    
    thresh = threshold_otsu(image)
    binary = image > thresh
    return binary


def Skeletonize_img():

    im = Get_binary(imread('image_bin.png'))
    im_ax = medial_axis(im)

    fig, axes = plt.subplots(nrows=1, ncols=2, sharex=True, sharey=True,
                        figsize=(8,8))

    ax = axes.ravel()

    ax[0].imshow(im, cmap=plt.cm.gray)
    ax[0].set_title('binary image')
 
    ax[1].imshow(im_ax, cmap=plt.cm.gray)
    ax[1].set_title('medial axis')
    

    plt.tight_layout()
    plt.show()  


Skeletonize_img()

from skimage import img_as_bool, io, color, morphology
import matplotlib.pyplot as plt

image = img_as_bool(color.rgb2gray(io.imread('image_bin.png')))
out = morphology.medial_axis(image)

f, (ax0, ax1) = plt.subplots(1, 2)
ax0.imshow(image, cmap='gray', interpolation='nearest')
ax1.imshow(out, cmap='gray', interpolation='nearest')
plt.show()

在图片周围添加黑色边框也会有所帮助