Minor and major axis inside elipse
2 ビュー (過去 30 日間)
古いコメントを表示
Hi. I want to plot axis inside elipse in front of my 7 figures, for checking the Orientation angle like that:


Code:
A = imread('4.png');
level = graythresh(A);
if level < 1
level = level +0.20
end
BW = im2bw(A,level);
figure(1), imshow(BW)
BW2 = imcomplement(BW);
figure(2), imshow(BW2)
s = regionprops(BW2, 'Orientation', 'MajorAxisLength', ...
'MinorAxisLength', 'Eccentricity', 'Centroid', 'Area');
imshow(BW2)
hold on
minArea=5000;
maxArea=40000;
list = find([s.Area] > minArea & [s.Area] < maxArea);
assignin('base','list',list);
display('Index list: ');
display(list);
for k = 1:numel(list)
k_iter = list(k);
c = s(k_iter).Centroid;
text(c(1), c(2)+20, sprintf('%d', k_iter),'HorizontalAlignment', 'center','VerticalAlignment', 'middle');
plot(c(1),c(2),'b*');
end
phi = linspace(0,2*pi,50);
cosphi = cos(phi);
sinphi = sin(phi);
for k = 1:length(s)
xbar = s(k).Centroid(1);
ybar = s(k).Centroid(2);
a = s(k).MajorAxisLength/2;
b = s(k).MinorAxisLength/2;
theta = pi*s(k).Orientation/180;
R = [ cos(theta) sin(theta)
-sin(theta) cos(theta)];
xy = [a*cosphi; b*sinphi];
xy = R*xy;
x = xy(1,:) + xbar;
y = xy(2,:) + ybar;
plot(x,y,'r','LineWidth',2);
end
hold off
Results:

0 件のコメント
回答 (1 件)
Image Analyst
2018 年 1 月 24 日
It's not so easy to find the largest ellipse than can fit inside the shapes. Why do you think you need this?
5 件のコメント
Image Analyst
2018 年 1 月 24 日
5 points are needed to define an ellipse. If you have less than that you'll have to determine the missing ones. You can perhaps take the "missing" ones as the ends of the major axis with the same major axis length as regionprops gives you. So take the convex hull with convhull(). Then if there are less than 5, use the orientation and major axis length to define points out on the tip of the long axis of the ellipse. Then you'll have 5 points and you can determine the ellipse. The attached paper may help.
参考
カテゴリ
Help Center および File Exchange で Polar Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
