Pick just some elements of a 3Dmatrix and then reshape them in the original size
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Simone Cotta Ramusino
am 27 Sep. 2022
Kommentiert: Simone Cotta Ramusino
am 28 Sep. 2022
I have a 105x142x145 matrix, representing a bone volume. The "background" pixel have a great larger volume than the others. Let's simplify it in a 5x4x2 for convenience and see an example (values are random):
E(:,:,1)=
5000 5000 5000 5000
5000 200 1000 5000
5000 66 190 1200
5000 5000 5000 5000
E(:,:,2)=
5000 5000 5000 5000
5000 400 250 5000
278 2900 190 500
5000 5000 5000 5000
I want to cluster them; to represent the volume, e.g. with labelvolshow, I need the bg pixels too. With kmeans, I can cluster them all, including bg pixels, in a very short time: I transform the volume in an array with (:) and then reshape the indexed pixel.
Now I have tried to cluster with the ward method, but I need to remove the bg pixel, so as not to take an infinite amount of time:
Z=clusterdata(tuttiE(tuttiE<max(tuttiE)),'Linkage','ward','SaveMemory','on','Maxclust',3);
The results seem ok, but I'd like to 3D-represent them and now I have an array that cannot be simply reshaped to the original volume, since it is missing the bg pixel. How can I rearrange it to the previous shape? I mean, transform [200,66,1000,190,1200,278,400,2900,250,190,500] to the original two matrices?
Thanks in advance
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 27 Sep. 2022
Assign
tuttiE<max(tuttiE)
into a variable, and use it to index tuttiE for clusterdata() purposes.
Then create an array of zeros the same size as tuttie and assign new values into that array indexed by the above mask. The locations not assigned into will retain the zero (or initialize to nan, or whatever is suitable for your purpose.)
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!