我正在尝试将此图像分为九个单独的区域(重叠的圆形区域)。由于圆圈重叠,我认为分水岭分割将是最好的方法。我按照this scikit-image.org example在图像上执行该技术,图像被过度分割,并且得到了10个片段,而不是9个片段,这已通过ndi.labels函数进行了检查。

在peak_local_max函数中增加覆盖区的大小会引起分段不足的问题,因此我认为最好是分段过度,然后合并应该是单个区域的区域。您可以在提供的输出中看到,第八个圆被分为两个单独的区域。我使用了regionprops函数来绘制边界框。

segmented_image_example.png

import matplotlib.pyplot as plt
from scipy import ndimage as ndi

from skimage import io, img_as_uint
from skimage.filters import median, threshold_minimum
from skimage.morphology import disk, square, closing, watershed
from skimage.feature import peak_local_max


image_bw = ('example_binary.tif')

distance = ndi.distance_transform_edt(image_bw)
local_maxi_disk10 = peak_local_max(distance, indices=False,
                                   footprint=np.ones((400, 400)),
                                   labels=image_bw)

markers, num_features = ndi.label(local_maxi_disk10)
labels = watershed(-distance, markers, mask=image_bw)
print('Number of features (ndi.label):', num_features)

fig, axes = plt.subplots(1, 3, figsize=(10, 4), sharex=True, sharey=True)
ax = axes.ravel()

ax[0].imshow(image_bw)
ax[0].set_title('Image Binary')
ax[1].imshow(-distance)
ax[1].set_title('Distances')
ax[2].imshow(labels)
ax[2].set_title('Separated objects')

for a in ax:
    a.set_axis_off()

plt.tight_layout()
plt.show()


最终目标是获取属于每个单独圆的图像部分,并将其另存为自己的图像,因此要合并不完整的区域,我可以将它们的边界框加在一起。但是,似乎应该有一种方法可以组合来自区域道具的多个区域,或者甚至可以组合分水岭过程本身的不同标签。有人可以帮助我向正确的方向发展,以便通过合并区域/标签来解决该问题吗?我还将附加使用的二进制图像。

example_binary.tif

最佳答案

您可能可以使用Region Adjacency Graph (RAG),然后根据某些条件[1] [2] [3]合并节点。但是,找到正确的标准通常很困难。

如果您想手动操作,可以使用NumPy索引:

import numpy as np

def merge_labels(labels_image,
                 labels_to_merge,
                 label_after_merge):
    labels_map = np.arange(np.max(labels_image) + 1)
    labels_map[labels_to_merge] = label_after_merge
    return labels_map[labels_image]

关于python - Skimage合并过度分割的区域,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57897326/

10-14 18:31
查看更多