Re: [问题] 从图片中撷取一个椭圆

楼主: KevinT (凯文踢)   2015-12-26 06:29:24
※ 引述《q1232431 (超级都可以)》之铭言:
: 想请问板上神人 小弟我想要在一张图片中撷取出来一个椭圆形,原本构想如下
: theta=0:pi/20:2*pi;
: alpha=pi/4;
: l=30;
: w=20;
: x0=100;
: y0=80;
: x3=x0+l*cos(alpha)*cos(theta)-w*sin(alpha)*sin(theta);
: y3=y0+l*sin(alpha)*cos(theta)+w*cos(alpha)*sin(theta);
: img(x3,y3,1:3) 其中x0 y0 是椭圆重心
: 不过发现这个方法不行,想请问有何方法,实在是想很久都想不到办法
因为现在x3 跟 y3里面只有包含椭圆的壳
如果想要撷取图片中一个椭圆,应该要定义椭圆里面的点,所以...
%%%
precision = pi/20;
theta=0:precision:2*pi;
alpha=pi/4;
x0=100;
y0=80;
xy = [];
for l = 0:0.5:30
for w = 0:0.5:20
tmp = [(x0+l*cos(alpha)*cos(theta)-w*sin(alpha)*sin(theta)).' ...
(y0+l*sin(alpha)*cos(theta)+w*cos(alpha)*sin(theta)).'];
tmp = unique(floor(tmp),'rows');
xy = cat(1,xy,tmp);
xy = unique(xy,'rows');
end
end
x3 = xy(:,1);
y3 = xy(:,2);
%%%
透过定义参数precision可以调整你的椭圆要多椭
Enjoy!

Links booklink

Contact Us: admin [ a t ] ucptt.com