필터 지우기
필터 지우기

The explanation of each step in ellipse fitting code

조회 수: 4 (최근 30일)
Walaa
Walaa 2023년 4월 6일
댓글: Matt J 2023년 4월 6일
I need help understanding each line of this code.
% Calculate centroid, orientation and major/minor axis length of the ellipse
s = regionprops(BW,{'Centroid','Orientation','MajorAxisLength','MinorAxisLength'});
% Calculate the ellipse line
theta = linspace(0,2*pi);
col = (s.MajorAxisLength/2)*cos(theta);
row = (s.MinorAxisLength/2)*sin(theta);
M = makehgtform('translate',[s.Centroid, 0],'zrotate',deg2rad(-1*s.Orientation));
D = M*[col;row;zeros(1,numel(row));ones(1,numel(row))];

채택된 답변

Matt J
Matt J 2023년 4월 6일
편집: Matt J 2023년 4월 6일
I've added some comments.
% Calculate centroid, orientation and major/minor axis length of the ellipse
s = regionprops(BW,{'Centroid','Orientation','MajorAxisLength','MinorAxisLength'});
theta = linspace(0,2*pi);
col = (s.MajorAxisLength/2)*cos(theta);
row = (s.MinorAxisLength/2)*sin(theta); %coordinates of points (col,row) on unrotated ellipse
M = makehgtform('translate',[s.Centroid, 0],'zrotate',deg2rad(-1*s.Orientation)); %rotation matrix
D = M*[col;row;zeros(1,numel(row));ones(1,numel(row))];%points on rotated ellipse
  댓글 수: 2
Walaa
Walaa 2023년 4월 6일
이동: Matt J 2023년 4월 6일
thanks you
Matt J
Matt J 2023년 4월 6일
You are quite welcome.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by