作者:
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!