Grouping data according to the connected components, which may have a value 1 unit different
1 回表示 (過去 30 日間)
古いコメントを表示
Dear all,
I am trying to group different values according to the value of their neighbors, which can have a difference value of 1. I show you an example with matrix to clarify my intention:
M = [0 1 0 0; 1 0 1 3; 0 1 0 2; 0 2 0 4]
I would like to get the following matrix:
M_groups=[0 1 0 0; 1 0 1 1; 0 1 0 1; 0 1 0 2];
I don't know how to proceed for a general case, I was thinking about the following conditions: If the cell has a non-zero value and a neighbor which is 1 unit higher or lower
Then, I should identify them somehow per groups, but I was not able to program this.
I have seen that there exists the function bwconncomp.m, but in my case I firstly need to obtain the binary image according to the condition about the difference of 1 unit between neighbors.
Could you please give me some insight about this? I would really appreciate your help.
Julia
3 件のコメント
Ashish Uthama
2011 年 3 月 16 日
As Jan asked, you need to define 'neighbors'.i.e are they four connected (two above and two on the side) or 8 connected (includes the diagonally adjacent 'neighbors').
What about 'cells' along the borders? How do you want to deal with them?
It would help to formulate your thoughts as pseudo code, it would make the question clear and might also just lead you to the solution. Something along these lines:
Consider one cell (or element) in the matrix
Take its four-connected neighbors
If any of these neighbors are 1 unit above or below current cell
Mark current cell as <> ...
Etc
採用された回答
Wolfgang Schwanghart
2011 年 3 月 18 日
You might want to take a look at Tim Davis' function find_components ( http://www.mathworks.com/matlabcentral/fileexchange/21366-findcomponents ). In combination with my function ixneighbors ( http://www.mathworks.com/matlabcentral/fileexchange/16991-neighbor-indexing ), I am sure you'll be able to compute your label matrix.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!