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

2 views (last 30 days)
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):
5000 5000 5000 5000
5000 200 1000 5000
5000 66 190 1200
5000 5000 5000 5000
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:
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

Accepted Answer

Walter Roberson
Walter Roberson on 27 Sep 2022
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.)

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!