我正在嘗試使用 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()


uj5u.com熱心網友回復:
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()
在影像周圍添加黑色邊框也會有所幫助
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/344527.html
標籤:Python 麻木的 opencv 图像处理 scikit-image
上一篇:高斯模糊的內核
