3D matrix with various chain!!
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (3)
Oleg Komarov
am 17 Aug. 2012
Bearbeitet: Oleg Komarov
am 17 Aug. 2012
If you have the Image Processing Toolbox:
CC = bwconncomp(U3);
labelmatrix(CC)
Image Analyst
am 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 Kommentare
Image Analyst
am 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
am 20 Aug. 2012
Change from OR to AND:
if any(topPlane(:)) && any(bottomPlane(:))
Hisham
am 20 Aug. 2012
Kategorien
Mehr zu Labels and Annotations finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!