Pick just some elements of a 3Dmatrix and then reshape them in the original size
조회 수: 2 (최근 30일)
이전 댓글 표시
Simone Cotta Ramusino
2022년 9월 27일
댓글: Simone Cotta Ramusino
2022년 9월 28일
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!