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

Home » Public Forums » archive » Cannot understand a part of the IDL routine!! pls help!!
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Cannot understand a part of the IDL routine!! pls help!! [message #70925] Fri, 21 May 2010 14:33 Go to next message
bala murugan is currently offline  bala murugan
Messages: 23
Registered: April 2010
Junior Member
The following is a part of the IDL routine for region grow. The
following three lines of code is used to define the pixels that is the
ROI pixels.
x = FINDGEN(16*16) MOD 16 + 276
y = LINDGEN(16*16) / 16 + 254
roiPixels = x + y * imgDims[0]

The question is how does it define the ROI pixels?
I dont see how it does........ Somebody please help me by giving a
simple and clear description.


Thanks,
B
Re: Cannot understand a part of the IDL routine!! pls help!! [message #71034 is a reply to message #70925] Tue, 25 May 2010 12:16 Go to previous messageGo to next message
Brian Daniel is currently offline  Brian Daniel
Messages: 80
Registered: July 2009
Member
On May 25, 3:13 pm, Brian Daniel <Daniels...@yahoo.com> wrote:
> On May 25, 9:23 am, Jeremy Bailin <astroco...@gmail.com> wrote:
>
>
>
>
>
>> On May 24, 1:26 pm, Brian Daniel <Daniels...@yahoo.com> wrote:
>
>>> On 24 May, 08:16, Jeremy Bailin <astroco...@gmail.com> wrote:
>
>>>> On May 23, 11:07 am, David Fanning <n...@dfanning.com> wrote:
>
>>>> > bala murugan writes:
>>>> > > The following is a part of the IDL routine for region grow. The
>>>> > > following three lines of code is used to define the pixels that is the
>>>> > > ROI pixels.
>>>> > > x = FINDGEN(16*16) MOD 16 + 276
>>>> > > y = LINDGEN(16*16) / 16 + 254
>>>> > > roiPixels = x + y * imgDims[0]
>
>>>> > > The question is how does it define the ROI pixels?
>>>> > > I dont see how it does........ Somebody please help me by giving a
>>>> > > simple and clear description.
>
>>>> > What is happening here is the IDL is turning one-dimensional
>>>> > image indices into two-dimensional image indices. Before
>>>> > the advent of the function Array_Indices, we always had
>>>> > to do this by hand. This code was obviously written in
>>>> > those long-ago dark days.
>
>>>> > Here is an article that explains this process in some
>>>> > detail:
>
>>>> >   http://www.dfanning.com/tips/where_to_2d.html
>
>>>> > Cheers,
>
>>>> > David
>
>>>> > --
>>>> > David Fanning, Ph.D.
>>>> > Fanning Software Consulting, Inc.
>>>> > Coyote's Guide to IDL Programming:http://www.dfanning.com/
>>>> > Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
>>>> Incidentally, is there an in-built routine that I've missed that does
>>>> the reverse mapping (multi-D to 1D)?  I know I've written my own and I
>>>> suspect others have too, but it seems like there ought to be a built-
>>>> in version.
>
>>>> -Jeremy.- Hide quoted text -
>
>>>> - Show quoted text -
>
>>> reform does the trick.  For example:
>>> image = indgen(20,30,3)
>>> help, image
>>> IMAGE           INT       = Array[20, 30, 3]
>>> image_vector = reform(image,20*30*3)
>>> help, image_vector
>>> IMAGE_VECTOR    INT       = Array[1800]
>
>>> -Brian
>
>> Yes, you can of course use l/indgen to give you a multi-D array that
>> you can use for the mapping (I'm not sure what the point of the reform
>> is - I would just use image[4,3,0] to find out the 1D index of the
>> point (4,3,0)). But it requires generating an auxiliary array with the
>> required dimensions, which can be very wasteful of memory in the
>> applications where I tend to use it!
>
>> -Jeremy.
>
> I was using indgen as an illustration.  I thought you were looking for
> a way to change a multi dimensional array into a vectorized array.  I
> see now you'd like the compliment to array_indices.pro.  Say you have
> an array of size x_dim, y_dim and z_dim.  The index of a particular
> point in the array (xi,yi,zi) is given as
> index = xi + yi * x_dim + zi * x_dim * y_dim.
>
> It can be generalized to N dimensions by
> index = x[0] + x[1]*dim[0] +x[2]*dim[1]*dim[0] + ... +
> x[N-1]*dim[N-2]*dim[N-3]*...*dim[0].
>
> I haven't seen a library routine that does it, but I usually only work
> in 2 or 3 dimensions and hardcode it in. Hope this helps.
>
> -Brian

Oh, and in the generalized case, x is a vector of size N consisting of
dimensional indices and dim is an N sized vector of the array
dimensions.
Re: Cannot understand a part of the IDL routine!! pls help!! [message #71035 is a reply to message #70925] Tue, 25 May 2010 12:13 Go to previous messageGo to next message
Brian Daniel is currently offline  Brian Daniel
Messages: 80
Registered: July 2009
Member
On May 25, 9:23 am, Jeremy Bailin <astroco...@gmail.com> wrote:
> On May 24, 1:26 pm, Brian Daniel <Daniels...@yahoo.com> wrote:
>
>
>
>
>
>> On 24 May, 08:16, Jeremy Bailin <astroco...@gmail.com> wrote:
>
>>> On May 23, 11:07 am, David Fanning <n...@dfanning.com> wrote:
>
>>>> bala murugan writes:
>>>> > The following is a part of the IDL routine for region grow. The
>>>> > following three lines of code is used to define the pixels that is the
>>>> > ROI pixels.
>>>> > x = FINDGEN(16*16) MOD 16 + 276
>>>> > y = LINDGEN(16*16) / 16 + 254
>>>> > roiPixels = x + y * imgDims[0]
>
>>>> > The question is how does it define the ROI pixels?
>>>> > I dont see how it does........ Somebody please help me by giving a
>>>> > simple and clear description.
>
>>>> What is happening here is the IDL is turning one-dimensional
>>>> image indices into two-dimensional image indices. Before
>>>> the advent of the function Array_Indices, we always had
>>>> to do this by hand. This code was obviously written in
>>>> those long-ago dark days.
>
>>>> Here is an article that explains this process in some
>>>> detail:
>
>>>>   http://www.dfanning.com/tips/where_to_2d.html
>
>>>> Cheers,
>
>>>> David
>
>>>> --
>>>> David Fanning, Ph.D.
>>>> Fanning Software Consulting, Inc.
>>>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>>>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
>>> Incidentally, is there an in-built routine that I've missed that does
>>> the reverse mapping (multi-D to 1D)?  I know I've written my own and I
>>> suspect others have too, but it seems like there ought to be a built-
>>> in version.
>
>>> -Jeremy.- Hide quoted text -
>
>>> - Show quoted text -
>
>> reform does the trick.  For example:
>> image = indgen(20,30,3)
>> help, image
>> IMAGE           INT       = Array[20, 30, 3]
>> image_vector = reform(image,20*30*3)
>> help, image_vector
>> IMAGE_VECTOR    INT       = Array[1800]
>
>> -Brian
>
> Yes, you can of course use l/indgen to give you a multi-D array that
> you can use for the mapping (I'm not sure what the point of the reform
> is - I would just use image[4,3,0] to find out the 1D index of the
> point (4,3,0)). But it requires generating an auxiliary array with the
> required dimensions, which can be very wasteful of memory in the
> applications where I tend to use it!
>
> -Jeremy.

I was using indgen as an illustration. I thought you were looking for
a way to change a multi dimensional array into a vectorized array. I
see now you'd like the compliment to array_indices.pro. Say you have
an array of size x_dim, y_dim and z_dim. The index of a particular
point in the array (xi,yi,zi) is given as
index = xi + yi * x_dim + zi * x_dim * y_dim.

It can be generalized to N dimensions by
index = x[0] + x[1]*dim[0] +x[2]*dim[1]*dim[0] + ... +
x[N-1]*dim[N-2]*dim[N-3]*...*dim[0].

I haven't seen a library routine that does it, but I usually only work
in 2 or 3 dimensions and hardcode it in. Hope this helps.

-Brian
Re: Cannot understand a part of the IDL routine!! pls help!! [message #71039 is a reply to message #70925] Tue, 25 May 2010 06:23 Go to previous messageGo to next message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On May 24, 1:26 pm, Brian Daniel <Daniels...@yahoo.com> wrote:
> On 24 May, 08:16, Jeremy Bailin <astroco...@gmail.com> wrote:
>
>
>
>
>
>> On May 23, 11:07 am, David Fanning <n...@dfanning.com> wrote:
>
>>> bala murugan writes:
>>>> The following is a part of the IDL routine for region grow. The
>>>> following three lines of code is used to define the pixels that is the
>>>> ROI pixels.
>>>> x = FINDGEN(16*16) MOD 16 + 276
>>>> y = LINDGEN(16*16) / 16 + 254
>>>> roiPixels = x + y * imgDims[0]
>
>>>> The question is how does it define the ROI pixels?
>>>> I dont see how it does........ Somebody please help me by giving a
>>>> simple and clear description.
>
>>> What is happening here is the IDL is turning one-dimensional
>>> image indices into two-dimensional image indices. Before
>>> the advent of the function Array_Indices, we always had
>>> to do this by hand. This code was obviously written in
>>> those long-ago dark days.
>
>>> Here is an article that explains this process in some
>>> detail:
>
>>>   http://www.dfanning.com/tips/where_to_2d.html
>
>>> Cheers,
>
>>> David
>
>>> --
>>> David Fanning, Ph.D.
>>> Fanning Software Consulting, Inc.
>>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
>> Incidentally, is there an in-built routine that I've missed that does
>> the reverse mapping (multi-D to 1D)?  I know I've written my own and I
>> suspect others have too, but it seems like there ought to be a built-
>> in version.
>
>> -Jeremy.- Hide quoted text -
>
>> - Show quoted text -
>
> reform does the trick.  For example:
> image = indgen(20,30,3)
> help, image
> IMAGE           INT       = Array[20, 30, 3]
> image_vector = reform(image,20*30*3)
> help, image_vector
> IMAGE_VECTOR    INT       = Array[1800]
>
> -Brian

Yes, you can of course use l/indgen to give you a multi-D array that
you can use for the mapping (I'm not sure what the point of the reform
is - I would just use image[4,3,0] to find out the 1D index of the
point (4,3,0)). But it requires generating an auxiliary array with the
required dimensions, which can be very wasteful of memory in the
applications where I tend to use it!

-Jeremy.
Re: Cannot understand a part of the IDL routine!! pls help!! [message #71054 is a reply to message #70925] Mon, 24 May 2010 11:26 Go to previous messageGo to next message
Brian Daniel is currently offline  Brian Daniel
Messages: 80
Registered: July 2009
Member
On 24 May, 08:16, Jeremy Bailin <astroco...@gmail.com> wrote:
> On May 23, 11:07 am, David Fanning <n...@dfanning.com> wrote:
>
>
>
>
>
>> bala murugan writes:
>>> The following is a part of the IDL routine for region grow. The
>>> following three lines of code is used to define the pixels that is the
>>> ROI pixels.
>>> x = FINDGEN(16*16) MOD 16 + 276
>>> y = LINDGEN(16*16) / 16 + 254
>>> roiPixels = x + y * imgDims[0]
>
>>> The question is how does it define the ROI pixels?
>>> I dont see how it does........ Somebody please help me by giving a
>>> simple and clear description.
>
>> What is happening here is the IDL is turning one-dimensional
>> image indices into two-dimensional image indices. Before
>> the advent of the function Array_Indices, we always had
>> to do this by hand. This code was obviously written in
>> those long-ago dark days.
>
>> Here is an article that explains this process in some
>> detail:
>
>>   http://www.dfanning.com/tips/where_to_2d.html
>
>> Cheers,
>
>> David
>
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> Incidentally, is there an in-built routine that I've missed that does
> the reverse mapping (multi-D to 1D)?  I know I've written my own and I
> suspect others have too, but it seems like there ought to be a built-
> in version.
>
> -Jeremy.- Hide quoted text -
>
> - Show quoted text -

reform does the trick. For example:
image = indgen(20,30,3)
help, image
IMAGE INT = Array[20, 30, 3]
image_vector = reform(image,20*30*3)
help, image_vector
IMAGE_VECTOR INT = Array[1800]


-Brian
Re: Cannot understand a part of the IDL routine!! pls help!! [message #71061 is a reply to message #70925] Mon, 24 May 2010 05:16 Go to previous messageGo to next message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On May 23, 11:07 am, David Fanning <n...@dfanning.com> wrote:
> bala murugan writes:
>> The following is a part of the IDL routine for region grow. The
>> following three lines of code is used to define the pixels that is the
>> ROI pixels.
>> x = FINDGEN(16*16) MOD 16 + 276
>> y = LINDGEN(16*16) / 16 + 254
>> roiPixels = x + y * imgDims[0]
>
>> The question is how does it define the ROI pixels?
>> I dont see how it does........ Somebody please help me by giving a
>> simple and clear description.
>
> What is happening here is the IDL is turning one-dimensional
> image indices into two-dimensional image indices. Before
> the advent of the function Array_Indices, we always had
> to do this by hand. This code was obviously written in
> those long-ago dark days.
>
> Here is an article that explains this process in some
> detail:
>
>   http://www.dfanning.com/tips/where_to_2d.html
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Incidentally, is there an in-built routine that I've missed that does
the reverse mapping (multi-D to 1D)? I know I've written my own and I
suspect others have too, but it seems like there ought to be a built-
in version.

-Jeremy.
Re: Cannot understand a part of the IDL routine!! pls help!! [message #71063 is a reply to message #70925] Sun, 23 May 2010 09:07 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
bala murugan writes:

> The following is a part of the IDL routine for region grow. The
> following three lines of code is used to define the pixels that is the
> ROI pixels.
> x = FINDGEN(16*16) MOD 16 + 276
> y = LINDGEN(16*16) / 16 + 254
> roiPixels = x + y * imgDims[0]
>
> The question is how does it define the ROI pixels?
> I dont see how it does........ Somebody please help me by giving a
> simple and clear description.

What is happening here is the IDL is turning one-dimensional
image indices into two-dimensional image indices. Before
the advent of the function Array_Indices, we always had
to do this by hand. This code was obviously written in
those long-ago dark days.

Here is an article that explains this process in some
detail:

http://www.dfanning.com/tips/where_to_2d.html

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Cannot understand a part of the IDL routine!! pls help!! [message #71111 is a reply to message #71035] Wed, 26 May 2010 05:51 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On May 25, 3:13 pm, Brian Daniel <Daniels...@yahoo.com> wrote:
> On May 25, 9:23 am, Jeremy Bailin <astroco...@gmail.com> wrote:
>
>
>
>
>
>> On May 24, 1:26 pm, Brian Daniel <Daniels...@yahoo.com> wrote:
>
>>> On 24 May, 08:16, Jeremy Bailin <astroco...@gmail.com> wrote:
>
>>>> On May 23, 11:07 am, David Fanning <n...@dfanning.com> wrote:
>
>>>> > bala murugan writes:
>>>> > > The following is a part of the IDL routine for region grow. The
>>>> > > following three lines of code is used to define the pixels that is the
>>>> > > ROI pixels.
>>>> > > x = FINDGEN(16*16) MOD 16 + 276
>>>> > > y = LINDGEN(16*16) / 16 + 254
>>>> > > roiPixels = x + y * imgDims[0]
>
>>>> > > The question is how does it define the ROI pixels?
>>>> > > I dont see how it does........ Somebody please help me by giving a
>>>> > > simple and clear description.
>
>>>> > What is happening here is the IDL is turning one-dimensional
>>>> > image indices into two-dimensional image indices. Before
>>>> > the advent of the function Array_Indices, we always had
>>>> > to do this by hand. This code was obviously written in
>>>> > those long-ago dark days.
>
>>>> > Here is an article that explains this process in some
>>>> > detail:
>
>>>> >   http://www.dfanning.com/tips/where_to_2d.html
>
>>>> > Cheers,
>
>>>> > David
>
>>>> > --
>>>> > David Fanning, Ph.D.
>>>> > Fanning Software Consulting, Inc.
>>>> > Coyote's Guide to IDL Programming:http://www.dfanning.com/
>>>> > Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
>>>> Incidentally, is there an in-built routine that I've missed that does
>>>> the reverse mapping (multi-D to 1D)?  I know I've written my own and I
>>>> suspect others have too, but it seems like there ought to be a built-
>>>> in version.
>
>>>> -Jeremy.- Hide quoted text -
>
>>>> - Show quoted text -
>
>>> reform does the trick.  For example:
>>> image = indgen(20,30,3)
>>> help, image
>>> IMAGE           INT       = Array[20, 30, 3]
>>> image_vector = reform(image,20*30*3)
>>> help, image_vector
>>> IMAGE_VECTOR    INT       = Array[1800]
>
>>> -Brian
>
>> Yes, you can of course use l/indgen to give you a multi-D array that
>> you can use for the mapping (I'm not sure what the point of the reform
>> is - I would just use image[4,3,0] to find out the 1D index of the
>> point (4,3,0)). But it requires generating an auxiliary array with the
>> required dimensions, which can be very wasteful of memory in the
>> applications where I tend to use it!
>
>> -Jeremy.
>
> I was using indgen as an illustration.  I thought you were looking for
> a way to change a multi dimensional array into a vectorized array.  I
> see now you'd like the compliment to array_indices.pro.  Say you have
> an array of size x_dim, y_dim and z_dim.  The index of a particular
> point in the array (xi,yi,zi) is given as
> index = xi + yi * x_dim + zi * x_dim * y_dim.
>
> It can be generalized to N dimensions by
> index = x[0] + x[1]*dim[0] +x[2]*dim[1]*dim[0] + ... +
> x[N-1]*dim[N-2]*dim[N-3]*...*dim[0].
>
> I haven't seen a library routine that does it, but I usually only work
> in 2 or 3 dimensions and hardcode it in. Hope this helps.
>
> -Brian

Yeah, I have a general solution for arbitrary numbers of dimensions in
JBIU:

http://web.astroconst.org/jbiu/jbiu-doc/misc/multi2index.htm l

I just wish there was a built-in version... I'm sure it would be more
efficient than mine, and when I tend to need this it's always when I'm
juggling enormous multi-dimensional arrays.

(incidentally, now that I look at that code again it occurs to me that
the PRODUCT and TOTAL calls should have the /INTEGER flag... going to
have to put out a major update soon).

-Jeremy.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Matching data in different time resolution
Next Topic: running an IDL .pro from outside IDL e.g. from a .bat file

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

Current Time: Wed Oct 08 15:12:15 PDT 2025

Total time taken to generate the page: 0.01125 seconds