How to draw a ellipses with known foci?
Show older comments
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.
Accepted Answer
More Answers (1)
Joseph Cheng
on 12 Nov 2014
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 Comments
Joy
on 12 Nov 2014
Joseph Cheng
on 12 Nov 2014
sooo... you would swap out my image. since i do not have yours. and my ellipsis parameters for yours.
Joy
on 23 Nov 2014
Categories
Find more on Geometric Transformation and Image Registration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!