Pick just some elements of a 3Dmatrix and then reshape them in the original size

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 27 Set 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 Commenti
Simone Cotta Ramusino
Simone Cotta Ramusino il 28 Set 2022
Ok, I'll recap it all to make sure I get it right:
I should take the overall vector tuttiE and get in another array the indices of the non-bg pixels.
Then I'll cluster the non-bg pixels and assign the indices obtained into the overall vector thanks to the positions I got before.
Finally, I can replace the bg pixel values not assigned with a value at will.
Is it correct?
Thanks again

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by