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.

 채택된 답변

Image Analyst
Image Analyst 2014년 11월 12일

0 개 추천

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

Image Analyst
Image Analyst 2014년 11월 12일
Or you can just use imellipse like in the attached example.
Ramesh Bala
Ramesh Bala 2018년 8월 7일
But the question is, he has just 2 focus and no major, minor length nor radii? So how is the burn_overlay_into_image.m (above) gonna be useful here?
Image Analyst
Image Analyst 2018년 8월 7일
I presume there are formulas in geometry that will give you the major and minor axis lengths given the foci.
Ramesh Bala
Ramesh Bala 2018년 8월 8일
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 2018년 8월 8일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Joseph Cheng
Joseph Cheng 2014년 11월 12일

0 개 추천

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
Joy 2014년 11월 12일
I tried your code, and it did help me draw an ellipse, but what I want here is to draw the ellipse on my binary image(matrix). Do you know how to achieve that?
Thanks!
Joseph Cheng
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
Joy 2014년 11월 23일
Thank you. I will try.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

태그

질문:

Joy
2014년 11월 12일

댓글:

2018년 8월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by