我有一些固定大小的字体字符图像,如输入图像示例所示。我想提取角色骨架(单像素宽)。我尝试了各种方法,如下所示,但输出都是不同的,不平滑。我认为一个像素宽的骨架将是平滑的(像素没有中断,没有噪声像素)。有更好的方法吗?如果没有,哪一个是最好的?在
输入图像样本
1)示例
from skimage import img_as_bool, io, color, morphology
import matplotlib.pyplot as plt
image = img_as_bool(color.rgb2gray(io.imread('image.jpeg')))
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()
输出1
2)示例
^{pr2}$输出2
3)示例
from skimage.morphology import skeletonize
from skimage import draw
from skimage.io import imread, imshow
from skimage.color import rgb2gray
import os
# load image from file
img_fname='D:\Ammar Data\Debbie_laptop_data\Ammar\sslab-deeplearning\GAN models\sslab_GAN\skeleton\hangul_1.jpeg'
image=imread(img_fname)
# Change RGB color to gray
image=rgb2gray(image)
# Change gray image to binary
image=np.where(image>np.mean(image),1.0,0.0)
# perform skeletonization
skeleton = skeletonize(image)
plt.imshow(skeleton)
输出3
您的代码很好,但是您可能需要更改将图像转换为二进制的方式。另外,为了避免看起来很嘈杂的输出,可以对骨架图像应用
binary_closing
。看看下面的代码-你的两张图片给了我下面的输出-
编辑: 为了避免在将图像转换为bool时丢失精度,还可以使用可用的thresholding algorithms之一对图像进行二值化。我喜欢大津的
^{pr2}$相关问题 更多 >
编程相关推荐