Create a cylindrical mask in a 3D matrix
Afficher commentaires plus anciens
Hi, I would like to create a mask in a 3D matrix in the shape of a cylinder. The reason why I want to do this is to analyse the properties of the MRI data within the mask only.
The following parameters are given:
- Coordinates of the center of the two faces of the cylinder.
- The radius of the cylinder.
- The size of the matrix.
Réponses (1)
- Coordinates of the center of the two faces of the cylinder. Call this c1,c2
- The radius of the cylinder. Call this r
- The size of the matrix. Call this [sx,sy,sz]
o=(c1+c2)/2; %origin
h=norm(c1(:)-c2(:)); %cylinder height
n=normalize(c1(:)-c2(:),'n')';
R=[n; null(n)']'; %rotation matrix
[I,J,K]=ndgrid((1:sx)-o(1),(1:sy)-o(2),(1:sz)-o(3));
C=[I(:),J(:),K(:)]*R; %rotated coordinates
mask=reshape( vecnorm(C,2,2)<=r & abs(C(:,1))<=h/2 ,sx,sy,sz);
Catégories
En savoir plus sur Image Segmentation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!