Python 3.x 平滑图像的锯齿状边缘
我想从图像中生成骨架。由于使用原始图像中的Python 3.x 平滑图像的锯齿状边缘,python-3.x,image-processing,scikit-image,Python 3.x,Image Processing,Scikit Image,我想从图像中生成骨架。由于使用原始图像中的skimage生成的边不平滑,因此从binary获得的结果骨架具有带结的断开边 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.m
skimage
生成的边不平滑,因此从binary
获得的结果骨架
具有带结的断开边
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()
我尝试使用explate
平滑锯齿状边缘。但是骨架中的轮廓具有两条边,而不是所需的单条边
我想询问有关如何平滑边的建议,以避免生成的骨架中出现结和断开连接的边
输入图像
输出图像
编辑:使用高斯平滑后
binary = image > thresh
gaussian = skimage.filters.gaussian(binary)
skeleton = skeletonize_3d(gaussian)
此中值滤波器应该对骨骼化的二值图像进行处理
import scipy
binary_smoothed = scipy.signal.medfilt (binary, 3)
对于边框,我可能会使用它并使用如下链接所示的参数
:
您是否尝试将“阈值”与“侵蚀/侵蚀”结合起来?撇渣不牢固,但通常阈值化后的侵蚀会减少留置权,而不需要sobel/canny-不确定skeletonize_3d在内部是否这样做。。。重复阈值和用高斯覆盖阈值图像可能会在执行其他步骤之前有所帮助。@PatrickArtner我尝试了gaussian=skimage.filters.gaussian(binary)
和skeletonize\u 3d(gaussian)
在binary=image>thresh
之后。现在已删除骨架中的结。但是边缘线不是连续的。请建议如何改进此操作?在应用骨架化之前,应在编辑中保留gaussian
变量。大概阈值应该低于内部使用的skeletonize_3d
。
from image_source_canny import canny
borders = canny (binary_smoothed, 3, 0.3, 0.2)