Path: news.mathworks.com!not-for-mail
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$1@fred.mathworks.com>
References: <g1bsct$ggh$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1211735522 11268 172.30.248.38 (25 May 2008 17:12:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 25 May 2008 17:12:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:470271


"elflord woods" <elflord.woods@gmail.com> wrote in message <g1bsct$ggh
$1@fred.mathworks.com>...
> 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

If

 X^2/a^2+Y^2/b^2

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