Pick just some elements of a 3Dmatrix and then reshape them in the original size
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2022-9-27
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.)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!