comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: creating elliptically shaped images
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: creating elliptically shaped images [message #37088 is a reply to message #37087] Mon, 24 November 2003 09:37 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
mruschin@hotmail.com (mark) writes:

> I'd like to form an image which has an elliptical shape and where all
> the pixels within this ellipse have values corresponding to any given
> function that I would specify, the simplest example being a uniform
> image (i.e. a value of 1 for all the pixels in the ellipse). Is there
> any nice way to do this in IDL or MATLAB other than looping through
> all the pixels and determining whether any given one lies within the
> ellipse?

You really have two questions. One is, how do I make a 2D function,
and the other is, how do I mask it to an elliptical shape? The
answers are close to the same for both. Making a 2D function is
usually very simple, as long as you expand your X and Y vectors to be
2D as well.

Let's say you have an N X-pixels and M Y-pixels, so your desired array
is IMG = fltarr(N,M). You would have a N-vector called X which labels
the X pixels, and an M-vector called Y which labels the y pixels.

Further suppose you have a

; Expand X and Y to full 2D arrays
XX = X # (fltarr(m)+1)
YY = (fltarr(n)+1) # Y

; Define ellipse
A = ... ;; semi-major axis
B = ... ;; semi-minor axis
U = (XX/A)^2 + (YY/B)^2
;; Ellipse 'radius' function is simply U
F_ELLIPSE = U

;; Make mask - any point inside the ellipse
MASK = F_ELLIPSE LT 1

;; Make your own user function
F_USER = F(XX,YY)

;; Finally, mask it so only points inside the ellipse are there
F_USER = F_USER * MASK



Now, anticipating your question, if you want an arbitrary position
angle and/or centroid, then you need to do a little extra work, but
not much. You would replace the U = ... line above with the
following:

C = cos(theta) & S = sin(theta)
XP = XX - XCENTROID & YP = YY - YCENTROID
U = ( (XP * (C/A) - YP * (S/A))^2 + (XP * (S/B) + YP * (C/WIDY))^2 )

and then continue.

Good luck!
Craig




--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Average outline of several contours
Next Topic: Code-correction please

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 14:52:13 PDT 2025

Total time taken to generate the page: 0.72111 seconds