平滑图像的锯齿边缘

时间:2018-11-28 11:59:10

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

我想从图像生成骨架。由于使用skimage从原始图像生成的边缘不平滑,因此从skeleton获得的结果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()

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

我想就如何平滑边缘以避免结skeleton中出现打结和边缘断开提出建议。

edit.jpg输入图片

output输出图像

编辑:使用高斯平滑后

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

enter image description here

1 个答案:

答案 0 :(得分:0)

此中值过滤器应该对二进制图像进行骨架化处理。

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)
相关问题