问题描述
我正在尝试分离连接的对象.似乎Python和分水岭算法(scipy实现)非常适合处理此问题.
I'm trying to separate connected objects. It seems that Python and the watershed algorithm (scipy implementation) are well-suited to handle this.
这是我的图像,它是自动生成的分水岭种子点(经过阈值和距离变换的图像的局部最大值):
Here is my image and automatically generated watershed seed points (local maxima of the thresholded and distance-transformed image):
seeds = myGenSeeds( image_grey )
到目前为止,太好了;每个对象都有种子.
So far, so good; there is a seed for every object.
但是,当我运行分水岭时,事情崩溃了:
Things break down when I run the watershed though:
segmented = ndimage.measurements.watershed_ift( 255 - image_grey, seeds)`
上中部群集和中央群集之间的距离差.在顶部群集中,一个对象淹没了其他两个对象.在中心群集中,尽管它可能太小而无法在此处看到,但中心种子仅泛滥到了几个像素.
Both the top-middle cluster and the centre cluster are poorly separated. In the top cluster, one object flooded around the other two. In the centre cluster, though it might be too small to see here, the centre seed flooded to only a few pixels.
我有两个问题:
- 分水岭算法是分离这样的对象的好选择吗?
- 如果是这样,我是否需要进行某种预处理以使图像更适合分水岭分割?
推荐答案
我发现此线程是因为我在watershed_ift
上遇到了同样的问题.我建议仅在skimage.morphology
中使用watershed
函数.它接受浮点输入,因此您不会在灰度图像上损失分辨率,并且实际上会淹没整个盆地,而ift
方法似乎只淹没标记所在的等值线.
I found this thread because I am having the same problem with watershed_ift
. I recommend just using the watershed
function in skimage.morphology
. It accepts float inputs, so you don't lose resolution on the greyscale image, and it actually floods the entire basin, while the ift
approach only seems to flood the isovalues where the markers lie.
请确保将距离变换乘以-1,以使峰变为谷,否则您将不会得到分水岭!
Be sure to multiply your distance transform by -1 so the peaks become valleys, or else you won't get any watersheds!
这篇关于具有分水岭的连接对象的图像分割的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!