Plot the MajorAxisLength and the MinorAxisLength - Matlab



我在下面的https://blogs.mathworks.com/steve/2010/07/30/visualizing-regionprops-ellipse-measurements/

我还想绘制MajorAxisLength和MinorAxisLength,我该怎么做?

脚本:

url = 'https://blogs.mathworks.com/images/steve/2010/rice_binary.png';
bw = imread(url);
imshow(bw)
s = regionprops(bw, 'Orientation', 'MajorAxisLength', ...
'MinorAxisLength', 'Eccentricity', 'Centroid');
imshow(bw)
hold on
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

您发布的内容中有很多不必要的代码。我不认为你真的试图根据你所说的你想策划的内容来调整它。鉴于您在评论中所说的内容,我认为这是您想要绘制长轴长度与短轴长度的代码

url = 'https://blogs.mathworks.com/images/steve/2010/rice_binary.png';
bw = imread(url);
s = regionprops(bw, 'Orientation', 'MajorAxisLength', ...
'MinorAxisLength', 'Eccentricity', 'Centroid'); %Get region props
Major=zeros(size(s)); 
Minor=zeros(size(s));
for k = 1:length(s)
Major(k)= s(k).MajorAxisLength; %get your y values
Minor(k)= s(k).MinorAxisLength; %get your x values
end
figure %create a new figure because you don't want to plot on top of the image
plot(Minor, Major, 'o') %plot
xlabel('Minor Axis Length')
ylabel('Major Axis Length')

相关内容

  • 没有找到相关文章

最新更新