查找 3D 椭球 matlab

Find 3D ellipsoid matlab

我在 Matlab 中遇到以下问题:我有一个对应于 3D ROI 的二进制 3D 体积 (NxNxN),我想找到最适合该 ROI 的椭圆体。我找到了中心的 3D 坐标、3D 半轴的长度和拟合椭球体的 3D 角度。结果向量类似于: [195.1126 169.3114 62.4193 28.2725 23.0191 9.3104 52.9536 -5.7639 1.7606] 其中前三个元素表示中心坐标,元素编号 4、5、6 表示半轴半径,元素编号 7、8、9分别表示 x、y、z 中的旋转度数。现在我想找到一个二进制 3D 体积(如 3D 矩阵:NxNxN,与原始 ROI 的大小相同),其中 0 在椭圆体之外,1 是椭圆体。 谁能帮我解决这个问题? 非常感谢。

试试这个:解释在评论中

     V = [195.1126 169.3114 62.4193,28.2725 23.0191 9.3104,52.9536 -5.7639 1.7606];
 c = V(1:3); % The centroid
 l = V(4:6); % Axis Length
 phi = -V(7:9); % Angles
 E = zeros(512,512,85); % initialize Elipse matrix
 R = rotx(phi(1))*roty(phi(2))*rotz(phi(3)); % Create rotation matrix around phi
 %%
 [X,Y,Z] = meshgrid(1:size(E,2),1:size(E,1),1:size(E,3)); % Create a Grid
 XYZr = ([X(:)-c(1),Y(:)-c(2),Z(:)-c(3)])*R; % rotate Grid and centralize around centroid
 %% Calculate the elipse equation
 inx = (((XYZr(:,1)))./l(1)); % 
 iny = (((XYZr(:,2)))./l(2));
 inz = (((XYZr(:,3)))./l(3));
 ind = [inx,iny,inz];

 E(:) = sum(ind.^2,2)<1;
 %% Display
 figure; imagesc(E(:,:,62));
 figure; imagesc(squeeze(E(:,195,:)));
 figure; imagesc(squeeze(E(170,:,:)));