形态蛇

形态蛇 1 是一系列用于图像分割的方法。它们的行为类似于活动轮廓的行为(例如, 测地线活动等高线 2不带边的活动轮廓 3) 。然而, 形态蛇 在二进制数组上使用形态运算符(如膨胀或侵蚀),而不是在浮点数组上求解偏微分方程组,后者是活动轮廓的标准方法。这使得 形态蛇 与传统的同类产品相比,速度更快,数值更稳定。

有两个 形态蛇 此实现中可用的方法: 形态测地线活动等高线 ( MorphGAC ,在函数中实现 morphological_geodesic_active_contour )和 无边缘的形态活动轮廓 ( MorphACWE ,在函数中实现 morphological_chan_vese )。

MorphGAC 适用于具有可见轮廓的图像,即使这些轮廓可能有噪声、杂乱或部分不清楚。然而,它需要对图像进行预处理以突出轮廓。这可以使用以下函数来完成 inverse_gaussian_gradient ,尽管用户可能想要定义他们自己的版本。产品的质量 MorphGAC 分割在很大程度上依赖于这一预处理步骤。

相反地, MorphACWE 当要分割的对象的内部和外部区域的像素值具有不同的平均值时,效果很好。不像 MorphGACMorphACWE 不要求对象的轮廓被很好地定义,并且它在原始图像上工作,而不需要任何预先处理。这使得 MorphACWE 更易于使用和调整 MorphGAC

参考文献

1

基于曲率的曲线和曲面演化的形态方法,Pablo Márquez-Neila,Luis Baumela和Luis阿尔瓦雷斯。在2014年IEEE模式分析和机器智能会刊(PAMI)中, DOI:10.1109/TPAMI.2013.106

2

测地线活动轮廓,Vicent Caselle,Ron Kimmel和Guillermo Sapiro。在1997年国际计算机视觉杂志(IJCV)中, DOI:10.1023/A:1007979827043

3

没有边的活动轮廓,陈可辛和卢米尼塔·维斯。在2001年IEEE图像处理会刊中, DOI:10.1109/83.902291

Morphological ACWE segmentation, Morphological ACWE evolution, Morphological GAC segmentation, Morphological GAC evolution
import numpy as np
import matplotlib.pyplot as plt
from skimage import data, img_as_float
from skimage.segmentation import (morphological_chan_vese,
                                  morphological_geodesic_active_contour,
                                  inverse_gaussian_gradient,
                                  checkerboard_level_set)


def store_evolution_in(lst):
    """Returns a callback function to store the evolution of the level sets in
    the given list.
    """

    def _store(x):
        lst.append(np.copy(x))

    return _store


# Morphological ACWE
image = img_as_float(data.camera())

# Initial level set
init_ls = checkerboard_level_set(image.shape, 6)
# List with intermediate results for plotting the evolution
evolution = []
callback = store_evolution_in(evolution)
ls = morphological_chan_vese(image, 35, init_level_set=init_ls, smoothing=3,
                             iter_callback=callback)

fig, axes = plt.subplots(2, 2, figsize=(8, 8))
ax = axes.flatten()

ax[0].imshow(image, cmap="gray")
ax[0].set_axis_off()
ax[0].contour(ls, [0.5], colors='r')
ax[0].set_title("Morphological ACWE segmentation", fontsize=12)

ax[1].imshow(ls, cmap="gray")
ax[1].set_axis_off()
contour = ax[1].contour(evolution[2], [0.5], colors='g')
contour.collections[0].set_label("Iteration 2")
contour = ax[1].contour(evolution[7], [0.5], colors='y')
contour.collections[0].set_label("Iteration 7")
contour = ax[1].contour(evolution[-1], [0.5], colors='r')
contour.collections[0].set_label("Iteration 35")
ax[1].legend(loc="upper right")
title = "Morphological ACWE evolution"
ax[1].set_title(title, fontsize=12)


# Morphological GAC
image = img_as_float(data.coins())
gimage = inverse_gaussian_gradient(image)

# Initial level set
init_ls = np.zeros(image.shape, dtype=np.int8)
init_ls[10:-10, 10:-10] = 1
# List with intermediate results for plotting the evolution
evolution = []
callback = store_evolution_in(evolution)
ls = morphological_geodesic_active_contour(gimage, 230, init_ls,
                                           smoothing=1, balloon=-1,
                                           threshold=0.69,
                                           iter_callback=callback)

ax[2].imshow(image, cmap="gray")
ax[2].set_axis_off()
ax[2].contour(ls, [0.5], colors='r')
ax[2].set_title("Morphological GAC segmentation", fontsize=12)

ax[3].imshow(ls, cmap="gray")
ax[3].set_axis_off()
contour = ax[3].contour(evolution[0], [0.5], colors='g')
contour.collections[0].set_label("Iteration 0")
contour = ax[3].contour(evolution[100], [0.5], colors='y')
contour.collections[0].set_label("Iteration 100")
contour = ax[3].contour(evolution[-1], [0.5], colors='r')
contour.collections[0].set_label("Iteration 230")
ax[3].legend(loc="upper right")
title = "Morphological GAC evolution"
ax[3].set_title(title, fontsize=12)

fig.tight_layout()
plt.show()

脚本的总运行时间: (0分5.215秒)

Gallery generated by Sphinx-Gallery