How to draw a ellipses with known foci?

8 views (last 30 days)
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

Image Analyst
Image Analyst on 12 Nov 2014
Joy, you can use the FAQ http://matlab.wikia.com/wiki/FAQ#How_do_I_create_an_ellipse.3F to get x and y coordinates, or use Joseph's code - either way. Then, to write into an image, you can just run through your x,y list:
for k = 1 : length(y);
row = round(y);
column = round(x);
binaryImage(row, column) = true;
end
  5 Comments
Ramesh Bala
Ramesh Bala on 8 Aug 2018
Thanks, I found this imellipse(gca,[10 10 50 150]) which literally needs xlim and ylim and not the focus values.
I believe with only foci values an ellipse can't be drawn.
Image Analyst
Image Analyst on 8 Aug 2018
It does not need xlim and ylim. It needs the width and height of the ellipse - those are different things. I'm sure a web search will provide the formula, which will involve another parameter. As you know, just having the foci doesn't define the ellipse. Remember the analogy of putting a string loop around the foci and drawing the ellipse with your pen? Well if the string is different lengths, you will get different size ellipses, right? So foci are not enough.

Sign in to comment.

More Answers (1)

Joseph Cheng
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
Joseph Cheng
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
Joy on 23 Nov 2014
Thank you. I will try.

Sign in to comment.

Categories

Find more on Brakes and Detents in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!