群集生长的blob [英] Cluster growing of blobs

查看:186
本文介绍了群集生长的blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下来自Mathworks的图片:

Consider the following image which is from Mathworks:

我已用

 [L, num]= bwlabel(I);

如何迭代连接所有blob,即启动一个blob并找到最近的一个blob 。考虑最左边的两个斑点,可以从斑点的许多点绘制许多线以连接到另一个斑点,但是可以通过找到最接近斑点的斑点的像素来获得最短的斑点。其他blob,在另一个blob中找到一个相似的像素并连接这两个像素。我想以这种方式连接它们。连接它们后,这使它们成为一个blob,找到最接近这个新blob的blob连接它们,等等在,直到所有整个图像都有一个封闭的结构?此外,blob并不总是圆形的,它们是随机的形状。

How do I connect all the blobs iteratively,i.e.start with one blob and find the nearest one to it.Consider the left-most two blobs, there can be many lines that can be drawn from many points of a blob to connect to the other blob, but the shortest one would be obtained by finding the pixel of a blob that is nearest to the other blob, find a similar pixel in the other blob and connect these two pixels.I would like connect them in this manner.After connecting them, which makes them a single blob, find the blob closest to this new blob connect them, and so on, until all the whole image has a single closed structure? Also, the blobs aren't always circular,they are of random shapes.

这里也提出了类似的问题:

Similar questions have been asked here:

如何查找使用MATLAB在两个blob(轮廓/闭合曲线)之间的最短路径?


http://in.mathworks.com/matlabcentral/newsreader/view_thread/270149

使用bwdist( ),我可以分离两个blob并使用蛮力方法通过测试第二个链接中提到的两个blob中的所有像素对来找到最短距离但是它需要很长时间。是否有更好的方法来处理这个问题这样可以更快地获得结果吗?

Using bwdist(), I could separate two blobs and use brute force approach to find the shortest distance by testing on all pairs of pixels in the two blobs as mentioned in the second link but it takes a really long time.Is there a better way to approach this so that the results can be obtained faster?

编辑:

这是另一张图片:

所需图片:

推荐答案

方法#1:连接质心点



Approach #1 : Connecting with the centroid points

%// Read image, convert to binary and remove some whitish border across it
im = im2bw(imread('http://i.stack.imgur.com/vUsrl.png'));
BW = im(3:end-2,3:end-2);
figure, imshow(BW), title('Starting/Original Image')

%// Find centroid points for each blob
cpts = reshape(round(struct2array(regionprops(BW,'Centroid'))),2,[])'; %//'

%// Initialize 2 groups- "hungry" & "feeder" groups, naming them as grp1 & grp2
grp1 = []; grp2 = cpts;

%// Initialize the blob index matching IDs
R = 1; C = 1;

while ~isempty(grp2)

    %// Get one from Group-2 into Group 1 based on the closest one that was
    %//obtained from the previous iteration. Remove that from Group -2.
    grp1 = [grp1 ; grp2(C,:)];
    grp2(C,:) = [];

    %// Find squared distances between those two groups
    sq_distmat = squared_dist(grp1,grp2);

    %// Find the IDs minimum one across row and column which would be the
    %IDs for group 1 and 2 respectively, calling them as R and C
    [~,idx] = min(sq_distmat(:));
    [R,C] = ind2sub(size(sq_distmat),idx);

    %// Draw the connecting line
    BW = linept(BW, grp1(R,2), grp1(R,1), grp2(C,2), grp2(C,1));

end
figure, imshow(BW), title('Final Connected Image')

相关函数 -

function sq_distmat = squared_dist(A,B)

[nA,dim] = size(A);
nB = size(B,1);

A_ext = ones(nA,dim*3);
A_ext(:,2:3:end) = -2*A;
A_ext(:,3:3:end) = A.^2;

B_ext = ones(nB,dim*3);
B_ext(:,1:3:end) = B.^2;
B_ext(:,2:3:end) = B;

sq_distmat = A_ext * B_ext.';

return;

动画乐趣 -

%// Read image, convert to binary and remove some whitish border across it
im = im2bw(imread('http://i.stack.imgur.com/vUsrl.png'));
BW = im(3:end-2,3:end-2);

%// Find boundary points as a cell array
bpts_cell = bwboundaries(BW);

%// Initialize 2 groups- "hungry" & "feeder" groups, naming them as grp1 & grp2
grp1c = []; grp2c = bpts_cell;

ID = 1;
for iter = 1:numel(bpts_cell)-1

    %// Get one from Group-2 into Group 1 based on the closest one that was
    %obtained from the previous iteration. Remove that from Group -2.
    grp1c = [grp1c ; grp2c(ID)];
    grp2c(ID,:) = [];
    grp1 = vertcat(grp1c{:});
    grp2 = vertcat(grp2c{:});

    %// Find squared distances between those two groups
    sq_distmat = squared_dist(grp1,grp2);

    %// Find the IDs minimum one across row and column which would be the
    %IDs for group 1 and 2 respectively, calling them as R and C
    [~,idx] = min(sq_distmat(:));
    [R,C] = ind2sub(size(sq_distmat),idx);

    %// Draw the connecting line
    BW = linept(BW, grp1(R,1), grp1(R,2), grp2(C,1), grp2(C,2));

    lens = cellfun('length',grp2c);
    clens = cumsum(lens);    
    ID = find(C<=clens,1);
end

动画乐趣 -

动画输出编辑图像 -

Animated output with the Edit image -

这篇关于群集生长的blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆