How to draw a ellipses with known foci?
이전 댓글 표시
Hi all,
I have a fixed foci in an image in Matlab, and I am wondering how to draw a ellipses with this known foci and get the pixels within the ellipses, and finally group these pixels into several sets according to their different distances to one foci point?
Thanks.
채택된 답변
추가 답변 (1개)
Joseph Cheng
2014년 11월 12일
To start your question you can do something like this where you setup your knowns. Here i don't know anything about your image so here i use one of the built in demo images where i say i know where i want my foci to be and then offset the plotted ellipse.
P = imread('bag.png');
imagesc(P),colormap gray,hold on;
axis equal
axis tight
%%location of foci
% foci to "center" ellipse onto
fociposxy = [123 165];
% ellipse parameters
a = 36;
b = 27;
%find the foci
foci = sqrt(a^2-b^2);
foci = [-foci foci];
%define ellipse
theta = 0:.1:2*pi;
x=a*sin(theta)+fociposxy(1)-foci(2);
y=b*cos(theta)+fociposxy(2);
plot(x,y,'r')
to find the pixels inside of the ellipse you can use the ellipse equation (x-offset)^2/a^2+(y-offset)^2/b^2<=1. where you would insert the x,y location of all the pixels and see if the equation hold true. Dunno what you mean by grouping by distance? are you looking for a bullseye coloring or actual grouping like region props does?
댓글 수: 3
Joy
2014년 11월 12일
Joseph Cheng
2014년 11월 12일
sooo... you would swap out my image. since i do not have yours. and my ellipsis parameters for yours.
Joy
2014년 11월 23일
카테고리
도움말 센터 및 File Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!