Plot the principle axes from regionprops3 over an isoplot of an ellipsoid

14 次查看(过去 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)

回答(1 个)

Yash
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);
Read more about vecnorm function here: https://in.mathworks.com/help/matlab/ref/vecnorm.html

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by