Ellipsoid Mask based on user input of dimension and euler angle

조회 수: 4 (최근 30일)
Shubham
Shubham 2024년 5월 2일
편집: Shubham 2024년 5월 3일
Actually I am trying to generate a 3d ellipsoid mask based on the user input of semi axes and euler angles. But in my code to do this I am calculating the distance of each pixel from the centre of the ellipse and then based on the ellipse equation pixels falling inside this ellipse are assigned true values. But the problem is that this operation is very tedious as I am scanning each and every pixel.
Any other way to do this which reduces the time complexity of this problem.

채택된 답변

Matt J
Matt J 2024년 5월 2일
편집: Matt J 2024년 5월 2일
An ellipsoid obeys the inequality (x-c)'*Q*(x-c)<=1 for some appropriate 3x3 matrix Q and 3x1 vector c (which is also the center of the ellipsoid). If you have it expressed this way, generation of the mask is very simple:
[dx,dy,dz]=ndgrid((1:nx)-c(1), (1:ny)-c(2)), (1:nz)-c(3) );
X=[dx(:),dy(:),dz(:)]';
mask = sum(X.*(Q*X))<=1;
mask=reshape(mask,nx, ny,nz);
  댓글 수: 2
Matt J
Matt J 2024년 5월 2일
편집: Matt J 2024년 5월 2일
To obtain Q from the euler angles, one way would be,
R=eul2rotm(angles); %Needs Robotics Toolbox
Q=R'\diag([a,b,c].^2)*R;
Shubham
Shubham 2024년 5월 3일
Thanks a lot sir, this was very helpful.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by