3D matrix with various chain!!
Show older comments
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
Accepted Answer
More Answers (3)
Oleg Komarov
on 17 Aug 2012
Edited: Oleg Komarov
on 17 Aug 2012
If you have the Image Processing Toolbox:
CC = bwconncomp(U3);
labelmatrix(CC)
Image Analyst
on 20 Aug 2012
topPlane = squeeze(U3(1, :, :));
bottomPlane = squeeze(U3(end, :, :));
if any(topPlane(:)) || any(bottomPlane(:))
break; % Bail out of the while loop.
end
6 Comments
Image Analyst
on 20 Aug 2012
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
on 20 Aug 2012
Change from OR to AND:
if any(topPlane(:)) && any(bottomPlane(:))
Hisham
on 20 Aug 2012
Categories
Find more on Labels and Annotations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!