From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to find pixels inside ellipse ?
Date: Sun, 25 May 2008 17:12:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 28
Message-ID: <g1c6l2$b04$>
References: <g1bsct$ggh$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1211735522 11268 (25 May 2008 17:12:02 GMT)
NNTP-Posting-Date: Sun, 25 May 2008 17:12:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:470271

"elflord woods" <> wrote in message <g1bsct$ggh
> hi all
> I have an ellipse region in an image and i know the size of
> the ellipse axes and its orientation
> how can i extract all the pixels inside this ellipse region .
> thanks
  I assume you also know the location of the ellipse's center.  Call that (x0,y0).  
Let t be the counterclockwise angle the major axis makes with respect to the 
x-axis.  Let a and b be the semi-major and semi-minor axes, respectively.  If 
P = (x,y) is an arbitrary point then do this:

 X = (x-x0)*cos(t)+(y-y0)*sin(t); % Translate and rotate coords.
 Y = -(x-x0)*sin(t)+(y-y0)*cos(t); % to align with ellipse



is less than 1, the point P lies inside the ellipse.  If it equals 1, it is right on 
the ellipse.  If it is greater than 1, P is outside.

Roger Stafford