3D matrix with various chain!!
显示 更早的评论
If I have U3 matrix as:
U3(:,:,1) = [
0 , 0 , 0 , 0 , 0;
0 , 0 , 0 , 0 , 0;
0 , 1 , 0 , 0 , 1;
0 , 0 , 0 , 0 , 0;
0 , 0 , 0 , 0 , 0
]
U3(:,:,2) = [
0 , 0 , 0 , 0 , 0;
0 , 0 , 0 , 0 , 0;
0 , 1 , 0 , 0 , 1;
0 , 1 , 0 , 0 , 0;
0 , 1 , 0 , 0 , 0
]
U3(:,:,3) = [
0 , 0 , 0 , 0 , 0;
0 , 0 , 0 , 0 , 0;
0 , 1 , 0 , 0 , 1;
0 , 0 , 0 , 0 , 0;
0 , 0 , 0 , 0 , 0
]
I assumed that these coordinates can be represented as an individual chain U3(3,2,1) and U3(3,2,2)and U3(4,2,2) and U3(5,2,2)and U3(3,2,3). and the other coordinates as another individual chain U3(3,4,1) and U3(3,4,2) and U3(3,4,3).
How can I give each chain a similar individual number? EX.
U3(3,2,1) and U3(3,2,2)and U3(4,2,2) and U3(5,2,2)and U3(3,2,3)=2
U3(3,4,1) and U3(3,4,2) and U3(3,4,3)=3
采纳的回答
更多回答(3 个)
Oleg Komarov
2012-8-17
编辑:Oleg Komarov
2012-8-17
If you have the Image Processing Toolbox:
CC = bwconncomp(U3);
labelmatrix(CC)
Image Analyst
2012-8-20
topPlane = squeeze(U3(1, :, :));
bottomPlane = squeeze(U3(end, :, :));
if any(topPlane(:)) || any(bottomPlane(:))
break; % Bail out of the while loop.
end
6 个评论
Image Analyst
2012-8-20
Perhaps I don't know what you mean. My code will enter the "if" if there is a 1 in the top row or bottom row of the three U3 planes you show. Both of your two examples have that so that's why both will display OK (in my code it would have hit the break line). If that's not what you want then explain what you want. For some irregularly shaped grouping of 1's, there is no "chain terminal" that I know of. Let's say the blob is shaped like a star. What is/are the terminals?
Image Analyst
2012-8-20
Change from OR to AND:
if any(topPlane(:)) && any(bottomPlane(:))
Hisham
2012-8-20
类别
在 帮助中心 和 File Exchange 中查找有关 Labels and Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!