斑点的集群生长
Cluster growing of blobs
考虑以下来自 Mathworks 的图像:
我用
标记了斑点
[L, num]= bwlabel(I);
我如何迭代地连接所有的斑点,i.e.start一个斑点并找到最接近it.Consider最左边的两个斑点的一个,可以从中绘制很多条线一个 blob 的许多点连接到另一个 blob,但是最短的点将通过找到一个 blob 的最接近另一个 blob 的像素来获得,在另一个 blob 中找到一个相似的像素并连接这两个 pixels.I 想在这个 manner.After 中连接它们,连接它们,这使它们成为一个单一的斑点,找到最接近这个新斑点的斑点连接它们,依此类推,直到整个图像都有一个单一的封闭结构?另外,斑点并不总是圆形的,它们的形状是随机的。
这里有人问过类似的问题:
How to find the shortest path between two blobs(contours/closed curves) using MATLAB?
和
http://in.mathworks.com/matlabcentral/newsreader/view_thread/270149
使用 bwdist(),我可以分离两个斑点并使用蛮力方法通过测试第二个 link 中提到的两个斑点中的所有像素对来找到最短距离,但它需要真的很长 time.Is 有更好的方法来解决这个问题以便更快地获得结果吗?
编辑:
这是另一张图片:
所需图片:
方法 #1:连接质心点
%// 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;
动画乐趣-
方法 #2:连接轮廓点
%// 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
动画乐趣-
使用编辑图像的动画输出 -
考虑以下来自 Mathworks 的图像:
我用
标记了斑点 [L, num]= bwlabel(I);
我如何迭代地连接所有的斑点,i.e.start一个斑点并找到最接近it.Consider最左边的两个斑点的一个,可以从中绘制很多条线一个 blob 的许多点连接到另一个 blob,但是最短的点将通过找到一个 blob 的最接近另一个 blob 的像素来获得,在另一个 blob 中找到一个相似的像素并连接这两个 pixels.I 想在这个 manner.After 中连接它们,连接它们,这使它们成为一个单一的斑点,找到最接近这个新斑点的斑点连接它们,依此类推,直到整个图像都有一个单一的封闭结构?另外,斑点并不总是圆形的,它们的形状是随机的。
这里有人问过类似的问题:
How to find the shortest path between two blobs(contours/closed curves) using MATLAB?
和
http://in.mathworks.com/matlabcentral/newsreader/view_thread/270149
使用 bwdist(),我可以分离两个斑点并使用蛮力方法通过测试第二个 link 中提到的两个斑点中的所有像素对来找到最短距离,但它需要真的很长 time.Is 有更好的方法来解决这个问题以便更快地获得结果吗?
编辑:
这是另一张图片:
所需图片:
方法 #1:连接质心点
%// 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;
动画乐趣-
方法 #2:连接轮廓点
%// 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
动画乐趣-
使用编辑图像的动画输出 -