Find group of points in an array of points

3 ビュー (過去 30 日間)
Ndilokelwa Luis
Ndilokelwa Luis 2015 年 5 月 26 日
回答済み: Walter Roberson 2015 年 5 月 26 日
I have a array x(i,j) where randomly x(i,j) = 1 or x(i,j) = 0. I need to find groups of x(i,j) adjacent to each other with x(i,j) = 1. Please help.

採用された回答

Ndilokelwa Luis
Ndilokelwa Luis 2015 年 5 月 26 日
[L, num] = bwlabel(BW, n) solved the problem. Thank you!

その他の回答 (3 件)

Joseph Cheng
Joseph Cheng 2015 年 5 月 26 日
Do you have access to the image processing toolbox? if so the function bwconncomp() maybe what you're looking for
  1 件のコメント
Joseph Cheng
Joseph Cheng 2015 年 5 月 26 日
While your response isn't an answer detecting 1's isn't the hard part. Do you have access to the image processing toolbox. bwconncomp() will detect and group adjacent 1's for you. If you do not post what you have created and we can figure out how to stop the infinite loop.

サインインしてコメントする。


Ndilokelwa Luis
Ndilokelwa Luis 2015 年 5 月 26 日
Hi Joseph. Actually I found the way to identify x(i,j) = 1. The problem is grouping adjacent x(i,j) = 1. I enter in an infinite loop and can't get out of that.

Walter Roberson
Walter Roberson 2015 年 5 月 26 日
B = [A, zeros(size(A,1),1)]';
[Br,Bc] = ind2sub(size(B), strfind(B(:)', [1 1]));
Arc = [Bc(:), Br(:)];
Arc will now be an N x 2 array of row and column indices into A where a [1 1] pair was found. If there are "runs" then there will be one row in Arc for each "left" pixel in the run, and those entries will occur one after another in Arc, so if A(8,17) is the start of a [1 1 1] run, then there will be a row in Arc for [8, 17] and the next row in Arc would be [8, 18].

カテゴリ

Help Center および File ExchangeGet Started with Image Processing Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by