随机游走者分割

随机游走算法 1 从一组标记多个阶段(2个或更多)的标记中确定图像的分割。求解各向异性扩散方程时,在标记物的位置启动示踪剂。如果相邻像素具有相似的值,则局部扩散系数会更大,因此很难在高梯度上进行扩散。每个未知像素的标签被归因于在该扩散过程中具有最高概率首先到达的已知标记的标签。

在本例中,两个阶段清晰可见,但数据噪声太大,无法仅从直方图进行分割。我们从灰度直方图的极值尾部确定两个相位的标志,并使用随机游走器进行分割。

1

基于随机游动的图像分割方法 首页--期刊主要分类--期刊细介绍--期刊细介绍肛门图案。马赫。英特尔。2006年11月28(11):1768-83 DOI:10.1109/TPAMI.2006.233

Noisy data, Markers, Segmentation
import numpy as np
import matplotlib.pyplot as plt

from skimage.segmentation import random_walker
from skimage.data import binary_blobs
from skimage.exposure import rescale_intensity
import skimage

# Generate noisy synthetic data
data = skimage.img_as_float(binary_blobs(length=128, seed=1))
sigma = 0.35
data += np.random.normal(loc=0, scale=sigma, size=data.shape)
data = rescale_intensity(data, in_range=(-sigma, 1 + sigma),
                         out_range=(-1, 1))

# The range of the binary image spans over (-1, 1).
# We choose the hottest and the coldest pixels as markers.
markers = np.zeros(data.shape, dtype=np.uint)
markers[data < -0.95] = 1
markers[data > 0.95] = 2

# Run random walker algorithm
labels = random_walker(data, markers, beta=10, mode='bf')

# Plot results
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 3.2),
                                    sharex=True, sharey=True)
ax1.imshow(data, cmap='gray')
ax1.axis('off')
ax1.set_title('Noisy data')
ax2.imshow(markers, cmap='magma')
ax2.axis('off')
ax2.set_title('Markers')
ax3.imshow(labels, cmap='gray')
ax3.axis('off')
ax3.set_title('Segmentation')

fig.tight_layout()
plt.show()

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

Gallery generated by Sphinx-Gallery