【问题标题】:Smoothing jagged edges of an image平滑图像的锯齿状边缘
【发布时间】:2019-04-30 07:59:45
【问题描述】:

我想从图像中生成骨架。由于使用skimage 从原始图像生成的边缘不平滑,因此从binary 获得的结果skeleton 具有带结的断开边缘。

import skimage
from skimage import data,io,filters
import numpy as np
import cv2
import matplotlib.pyplot as plt
from skimage.filters import threshold_adaptive,threshold_mean
from skimage.morphology import binary_dilation
from skimage import feature
from skimage.morphology import skeletonize_3d

imgfile = "edit.jpg"
image = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
thresh = threshold_mean(image)
binary = image > thresh
edges = filters.sobel(binary)
dilate = feature.canny(binary,sigma=0)
skeleton = skeletonize_3d(binary)
fig, axes = plt.subplots(nrows=2,ncols=2, figsize=(8, 2))
ax = axes.ravel()

ax[0].imshow(binary, cmap=plt.cm.gray)
ax[0].set_title('binarize')

ax[1].imshow(edges, cmap=plt.cm.gray)
ax[1].set_title('edges')

ax[2].imshow(dilate, cmap=plt.cm.gray)
ax[2].set_title('dilates')

ax[3].imshow(skeleton, cmap=plt.cm.gray)
ax[3].set_title('skeleton')

for a in ax:
    a.axis('off')

plt.show()

我尝试使用dilate 来平滑锯齿状边缘。但是skeleton 中的轮廓有两条边,而不是所需的一条边。

我想就如何使边缘平滑以避免在生成的skeleton 中出现结和断开的边缘寻求建议。

输入图片

输出图片

编辑:使用高斯平滑后

binary = image > thresh
gaussian = skimage.filters.gaussian(binary)
skeleton = skeletonize_3d(gaussian)

【问题讨论】:

  • 您是否尝试将“阈值”与“侵蚀/侵蚀”结合起来? skimage 不牢固,但通常阈值处理后的侵蚀应该减少留置权而无需 sobel/canny - 不确定这是否是skeletonize_3d 在内部所做的......重复阈值 && 用高斯遮盖阈值图像之前可能会有所帮助做其他步骤。
  • @PatrickArtner 我在binary = image > thresh 之后尝试了gaussian = skimage.filters.gaussian(binary) 和skeleton = skeletonize_3d(gaussian)。现在skeleton 中的结已被移除。但边缘线不连续。请您建议如何这样做可以改进吗?
  • 在应用骨架化之前,您应该在编辑中保留gaussian 变量。据推测,阈值应该低于skeletonize_3d 内部使用的阈值。

标签: python-3.x image-processing scikit-image


【解决方案1】:

这个中值滤波器应该对你的二值图像进行骨架化。

import scipy
binary_smoothed = scipy.signal.medfilt (binary, 3)

对于边框,我可能会使用它并使用以下链接中显示的参数 https://claudiovz.github.io/scipy-lecture-notes-ES/advanced/image_processing/auto_examples/plot_canny.html:

from image_source_canny import canny
borders = canny (binary_smoothed, 3, 0.3, 0.2)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-10
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多