图像分割Matlab

时间:2017-06-14 11:28:15

标签: matlab image-processing image-segmentation image-morphology

我有这张BW图像:

Mask Object Connected

使用RegionProps函数,它显示某些对象已连接:Region Props

所以我使用像imerode这样的形态学操作来分离物体以获得它们的质心:Objects separated Centroids

现在我将每个对象的所有质心分开,但是在侵蚀区域时我丢失了很多信息,就像你在图3中看到的与图片1相比。 所以我在想是否有“扩张”图片3直到更接近图片1但没有再次连接对象。

2 个答案:

答案 0 :(得分:3)

你可能想看看bwmorph()。使用' thicken',inf名称 - 值对,它会加厚标签,直到它们重叠。它是一种简洁的分割工具。我们可以使用它为原始图像创建分割边框。

bw是原始图像。 标签是侵蚀标签的图像。

lines = bwmorph(labels, 'thicken', inf);

Image of segmentation lines

 segmented_bw = bw & lines

enter image description here

您还可以跳过几个阶段,并使用基于标记的分水岭获得类似的结果。或者甚至更好,因为形态跷跷板已经破坏了一些信息,如右下方分割不良的群集所示。

答案 1 :(得分:1)

您可以将蒙版中的每个白色像素分配到最近的质心,并使用生成的标签贴图:

[y x]= find(bw);  % get coordinates of mask pixels
D = pdist2([x(:), y(:)], [cx(:), cy(:)]);  % assuming cx, cy are centers' coordinates
[~, lb] = min(D, [], 2); % find index of closest center
lb_map = 0*bw;
lb_map(bw) = lb; % should give you the map.

有关详细信息,请参阅pdist2