python - 细化/骨骼化扭曲了我的形象

标签 python opencv image-processing computer-vision scikit-image

我正在尝试缩小此图像,但它会不断失真。

enter image description here

enter image description here

这是我应用细化的相关代码。我也尝试过使用“thin”功能而不是“skeletonize”,但结果相似。

from skimage.morphology import skeletonize, thin
new_im = cv2.imread(im_pth)
gray = cv2.cvtColor(new_im, cv2.COLOR_BGR2GRAY)
ske = (skeletonize(gray//255) * 255).astype(np.uint8)
cv2.imshow("image", gray)
cv2.waitKey(0)
cv2.destroyAllWindows()

我的目标是在细化后获得类似于此的形状:

enter image description here

我究竟做错了什么?我在网上阅读了有时jpg文件会导致问题的信息,但是我在该 Realm 没有经验来确认这一点。

最佳答案

我不确定从输入图像到二进制的转换是否正确。这是使用scikit-image函数的版本,似乎可以满足您的要求:

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

image = img_as_float(color.rgb2gray(io.imread('char.png')))
image_binary = image < 0.5
out_skeletonize = morphology.skeletonize(image_binary)
out_thin = morphology.thin(image_binary)


f, (ax0, ax1, ax2) = plt.subplots(1, 3, figsize=(10, 3))

ax0.imshow(image, cmap='gray')
ax0.set_title('Input')

ax1.imshow(out_skeletonize, cmap='gray')
ax1.set_title('Skeletonize')

ax2.imshow(out_thin, cmap='gray')
ax2.set_title('Thin')

plt.savefig('/tmp/char_out.png')
plt.show()

skeletonization and thinning in skimage

关于python - 细化/骨骼化扭曲了我的形象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49097972/

相关文章:

python - 获取模拟 file.read() 的实际返回值

python - Google Colab不显示图片

c++ - Opencv Mat内存管理

python - 如何使用函数式方法将数字列表转换为 python 中当前元素的数字总和列表?

python - 暂停并继续秒表

python - 无法使用 [OpenCV] cv2.VideoCapture.set() 设置帧宽度和高度

c++ - 基于生产者-消费者的多线程图像处理

python-3.x - 从图像中裁剪矩形纸

python - Python中彩色图像的快速四元数傅立叶变换

android - 如何在 Windows 中使用 Python-for-Android 创建一个包?