Find continuous elements in matrix
7 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
my problem is the following: i've one matrix made of two possible values (i.e. 1 and 0). I also have the coordinates of one "starting point". I would like to select all the ones that are connected to this point without selecting the ones that are separeted by zeros. I can't figure out a way to solve the problem... can you help me?
Thanks in advance, Fabio
采纳的回答
Andrei Bobrov
2012-6-18
use functions bwlabel and regionprops from Image Processing Toolbox
eg
youridx = {10,6}; % coordinates of one "starting point" (row - 10, column - 6)
a = [...
0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 1
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 1 0
0 0 1 0 1 0 0 1 0 0
0 1 0 0 0 0 0 0 1 0
0 0 1 0 0 0 0 1 0 0
0 0 0 0 1 1 1 0 0 0];
S = regionprops(a~=0,'PixelList');
t = bwlabel(a);
out = = fliplr(S(t(idx{:})).PixelList);
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!