Plot the principle axes from regionprops3 over an isoplot of an ellipsoid
9 次查看(过去 30 天)
显示 更早的评论
I have a problem where I have a binary image stack which I process with regionprops3. I can recover the principle axes directions and scaling from this function but when I plot them the output does not appear to be related to the ellipsoid at all. I have tried plotting both the rows and columns of the eigenvector matrix from regionprops3 but nothing seems to work.
As an example:
%%Example Code
x = 0:1:100
y = 0:1:100
z = 0:1:100
dx = .1
[X,Y,Z] = meshgrid(x,y,z);
%Define an ellipse
ell = 1*(X-50).^2 + 100*(Y-50).^2 + 3*(Z-50).^2 + 3*(Z-50).*(X-50) < 500 ;
T = regionprops3(ell ,'PrincipalAxisLength', 'Orientation' , 'centroid','EigenVectors','EigenValues')
c=T.Centroid
%Principle axes ?
axis_mat= ( (T.EigenVectors{1}) *(diag( (T.PrincipalAxisLength) ) ) )
%plot principle axis vectors
figure(1)
quiver3(c(1),c(2) ,c(3) , axis_mat(1,1),axis_mat(2,1),axis_mat(3,1))
hold on
quiver3(c(1),c(2) ,c(3), axis_mat(1,2),axis_mat(2,2),axis_mat(3,2))
quiver3(c(1),c(2) ,c(3), axis_mat(1,3),axis_mat(2,3),axis_mat(3 ,3))
xlim( [0,100] )
ylim( [0,100 ] )
zlim( [0,100 ] )
xlabel('X')
ylabel('Y' )
zlabel('Z')
%plot ellipsoid
isosurface(X,Y,Z,(ell),1 - 1e-6)
alpha(.2)
0 个评论
回答(1 个)
Yash
2024-2-13
The issue with your code is that the quiver3 function expects the direction vectors to be normalized. In your code, you are directly using the eigenvectors as the direction vectors, which are not normalized. To fix this, you need to normalize the eigenvectors before plotting them. You can normalize the eigenvectors using the vecnorm function before plotting them with quiver3.
% Normalize the eigenvectors
axis_mat = axis_mat ./ vecnorm(axis_mat);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!