【问题标题】:how to draw oval shape around objects in image如何在图像中的对象周围绘制椭圆形
【发布时间】:2014-11-16 00:19:20
【问题描述】:

我想在二进制图像中的单元格周围绘制椭圆形。到目前为止,我尝试使用下面显示的代码在二进制图像中的单元格周围绘制椭圆。在代码中,IBord 是二进制图像。代码在单元格周围成功绘制了椭圆形状。

s = regionprops(IBord, 'Orientation', 'MajorAxisLength', 'MinorAxisLength',    'Eccentricity', 'Centroid');
figure(2);
imshow(IBord)


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

请建议我如何修改此代码以在二进制图像中的单元格周围绘制椭圆形(蛋形)。

【问题讨论】:

标签: matlab matlab-figure


【解决方案1】:

实现此效果的一种方法是在cosphisinphi 上使用较小的指数。

gam = .8
xy = [a * sign(cosphi) .* abs(cosphi).^gam;  b * sign(sinphi) .* abs(sinphi).^gam];

玩转gam。这应该会产生更多椭圆形。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-11-23
  • 1970-01-01
  • 2021-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-18
相关资源
最近更新 更多