|
Re: creating elliptically shaped images [message #37087 is a reply to message #37072] |
Mon, 24 November 2003 09:48  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Matt Feinstein writes:
> I'll bet the people in the Matlab group you cross-posted to are
> wondering what you're talking about...
Those guys over there better get used to me.
I'm beginning to *like* Matlab! :-)
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: creating elliptically shaped images [message #37088 is a reply to message #37087] |
Mon, 24 November 2003 09:37  |
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
------------------------------------------------------------ --------------
|
|
|
Re: creating elliptically shaped images [message #37090 is a reply to message #37088] |
Mon, 24 November 2003 09:32  |
K. Bowman
Messages: 330 Registered: May 2000
|
Senior Member |
|
|
In article <a9116224.0311240712.618f4088@posting.google.com>,
mruschin@hotmail.com (mark) wrote:
> 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?
>
> Mark
I think this does the trick.
Ken Bowman
nx = 300
ny = 300
a = 0.75
b = 0.50
x = 2.0*((FINDGEN(nx)+0.5)/nx - 0.5)
y = 2.0*((FINDGEN(nx)+0.5)/nx - 0.5)
xx = REBIN(x, nx, ny, /SAMPLE)
yy = REBIN(REFORM(y, 1, ny), nx, ny, /SAMPLE)
ellipse = 255*(xx^2/a + yy^2/b LT 1.0)
WINDOW, XSIZE = 300, YSIZE = 300
TV, ellipse
|
|
|
Re: creating elliptically shaped images [message #37091 is a reply to message #37090] |
Mon, 24 November 2003 09:15  |
Matt Feinstein
Messages: 33 Registered: July 2002
|
Member |
|
|
On Mon, 24 Nov 2003 08:55:21 -0700, David Fanning <david@dfanning.com>
wrote:
> 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?
>
> I'd use the IDLanROI object to make an ROI out of
> your ellipse. Then you can easily create an image
> mask, see if a point is inside or outside the ROI, etc.
>
> Cheers,
>
> David
I'll bet the people in the Mtlab group you cross-posted to are
wondering what you're talking about...
Matt Feinstein
--
There is no virtue in believing something that can be proved to be true.
|
|
|
Re: creating elliptically shaped images [message #37096 is a reply to message #37091] |
Mon, 24 November 2003 08:36  |
Steven Lord
Messages: 1 Registered: November 2003
|
Junior Member |
|
|
mark wrote:
> 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?
It sounds like you want either a contour plot or an isosurface plot, or
something along those lines. See HELP CONTOUR and HELP ISOSURFACE, and look
at the examples in the Volume Visualization Techniques chapter of the Using
MATLAB Graphics manual.
--
Steve Lord
slord@mathworks.com
|
|
|
Re: creating elliptically shaped images [message #37098 is a reply to message #37096] |
Mon, 24 November 2003 07:55  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
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?
I'd use the IDLanROI object to make an ROI out of
your ellipse. Then you can easily create an image
mask, see if a point is inside or outside the ROI, etc.
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|