Re: Array indices and lookup tables [message #39712] |
Thu, 10 June 2004 06:59  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
David Fanning writes:
> Well, if that's the case, then here is an example that works,
> more or less:
Whoops! Not exactly the right example. But in the right
direction, I think. :-)
Maybe I can work on it more later. Have to go...
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Array indices and lookup tables [message #39713 is a reply to message #39712] |
Thu, 10 June 2004 06:57   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Haje Korth writes:
> oops, you are right, the 360 should have been a 720. I have worked with
> triangulate and trigrid in the past and what I learned is that you do NOT
> use these in time-critical operations. This is even slower than looping
> through a lookup table.
Well, if that's the case, then here is an example that works,
more or less:
IDL> filename = Filepath(Subdir=['examples', 'data'], 'rose.jpg')
IDL> Read_JPEG, filename, rose
IDL> help, rose
ROSE BYTE = Array[3, 227, 149]
IDL> a=indgen(227,149) ; Look-up table
IDL> a = shift(a, 100) ; Shift it so it looks different
IDL> r = bytarr(3, 227, 149) ; The new image, r.
IDL> r[0,*,*] = (rose[0,*,*])[a]
IDL> r[1,*,*] = (rose[1,*,*])[a]
IDL> r[2,*,*] = (rose[2,*,*])[a]
IDL> window, xsize=2*227, ysize=149
IDL> tv, rose, 0, true=1
IDL> tv, r, 1, true=1
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Array indices and lookup tables [message #39714 is a reply to message #39713] |
Thu, 10 June 2004 06:11   |
Haje Korth
Messages: 651 Registered: May 1997
|
Senior Member |
|
|
Christopher,
oops, you are right, the 360 should have been a 720. I have worked with
triangulate and trigrid in the past and what I learned is that you do NOT
use these in time-critical operations. This is even slower than looping
through a lookup table.
Cheers,
Haje
"Christopher Lee" <cl@127.0.0.1> wrote in message
news:20040610.093904.771151432.32286@buckley.atm.ox.ac.uk...
> In article <ca72v6$qlb$1@aplcore.jhuapl.edu>, "Haje Korth"
> <haje.korth@jhuapl.edu> wrote:
>
>
>> Good morning all,
>> I am working on a coordinate transformation for a map and I have a
>> simple problem. My mind is alreay blocked early in the morning and I
>> could use some input: I have an rgb image of dimensions [3,1440, 720]. I
>> need to rearranged the pixel in the image according to a lookup table of
>> dimension [2,1440,360], which contains the column and row of the new
>> pixel assigned to a location. Is there a magic way to do this without
>> looping through each pixel in IDL?
>> Thanks for helping,
>> Haje
>>
>
> The lookup table....Why is there only 360 points in the third dimension,
> not 720?
>
> I'm assuming the dimensions go as:
> 1st: [column, row]
> 2nd: new X location
> 3rd: new Y location
>
> If the 2nd and 3rd dimensions are the location of the point in the new
> image then you have a list of 1440*360
> points linking the old coordinates to the new grid?
>
> TRIANGULATE and TRIGRID should work then? using the XOUT and YOUT
> keywords to set your output grid.
>
>
> Chris.
|
|
|
Re: Array indices and lookup tables [message #39719 is a reply to message #39714] |
Thu, 10 June 2004 01:39   |
Chris Lee
Messages: 101 Registered: August 2003
|
Senior Member |
|
|
In article <ca72v6$qlb$1@aplcore.jhuapl.edu>, "Haje Korth"
<haje.korth@jhuapl.edu> wrote:
> Good morning all,
> I am working on a coordinate transformation for a map and I have a
> simple problem. My mind is alreay blocked early in the morning and I
> could use some input: I have an rgb image of dimensions [3,1440, 720]. I
> need to rearranged the pixel in the image according to a lookup table of
> dimension [2,1440,360], which contains the column and row of the new
> pixel assigned to a location. Is there a magic way to do this without
> looping through each pixel in IDL?
> Thanks for helping,
> Haje
>
The lookup table....Why is there only 360 points in the third dimension,
not 720?
I'm assuming the dimensions go as:
1st: [column, row]
2nd: new X location
3rd: new Y location
If the 2nd and 3rd dimensions are the location of the point in the new
image then you have a list of 1440*360
points linking the old coordinates to the new grid?
TRIANGULATE and TRIGRID should work then? using the XOUT and YOUT
keywords to set your output grid.
Chris.
|
|
|
|
|
Re: Array indices and lookup tables [message #39754 is a reply to message #39753] |
Wed, 09 June 2004 07:06   |
Haje Korth
Messages: 651 Registered: May 1997
|
Senior Member |
|
|
David,
damn, I was sure you had your coffee already by now. But then again, I am
two hours ahead of you. :-) To answer your question: Yes, I am *sure* I need
the lookup table. What I am doing is to transform a geographic map to
geomagnetic coordinates. Now, this would not be so bad if it only had to be
done once. But the map is composed out of two maps forming a day and a
nightside. The composition thus depends upon time of day as well as on
season. It is impossible to create images for all possible times and thus
they need to be created on the fly. As you can imagine I try to avoid having
to drink a whole pot of coffee until the conversion is completed. :-)
Since the conversion between geomagnetic and geographic coordinates is
nearly fixed a lookup table will do the job nicely. Is there a one line
command that will do the job using the right number of [ and ] in the right
order? Well, anything will do that prevents me from loopong through 1
million+ elements.
Cheers,
Haje
"David Fanning" <davidf@dfanning.com> wrote in message
news:MPG.1b30c1a7910a91fa989789@news.frii.com...
> Haje Korth writes:
>
>> I am working on a coordinate transformation for a map and I have a
simple
>> problem. My mind is alreay blocked early in the morning and I could use
some
>> input: I have an rgb image of dimensions [3,1440, 720]. I need to
rearranged
>> the pixel in the image according to a lookup table of dimension
>> [2,1440,360], which contains the column and row of the new pixel
assigned to
>> a location. Is there a magic way to do this without looping through each
>> pixel in IDL?
>
> Oh, dear. Come back after I've had a couple of cups
> of coffee, would you. :-(
>
> Cheers,
>
> David
>
> P.S. With the (what!?) thousand different map projections
> now in IDL, are you *sure* you need a look-up table? :-)
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Array indices and lookup tables [message #39755 is a reply to message #39754] |
Wed, 09 June 2004 06:42   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Haje Korth writes:
> I am working on a coordinate transformation for a map and I have a simple
> problem. My mind is alreay blocked early in the morning and I could use some
> input: I have an rgb image of dimensions [3,1440, 720]. I need to rearranged
> the pixel in the image according to a lookup table of dimension
> [2,1440,360], which contains the column and row of the new pixel assigned to
> a location. Is there a magic way to do this without looping through each
> pixel in IDL?
Oh, dear. Come back after I've had a couple of cups
of coffee, would you. :-(
Cheers,
David
P.S. With the (what!?) thousand different map projections
now in IDL, are you *sure* you need a look-up table? :-)
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Array indices and lookup tables [message #39799 is a reply to message #39714] |
Thu, 10 June 2004 10:15  |
Chris Lee
Messages: 101 Registered: August 2003
|
Senior Member |
|
|
In article <ca9mms$f24$1@aplcore.jhuapl.edu>, "Haje Korth"
<haje.korth@jhuapl.edu> wrote:
> Christopher,
> oops, you are right, the 360 should have been a 720. I have worked with
> triangulate and trigrid in the past and what I learned is that you do
> NOT use these in time-critical operations. This is even slower than
> looping through a lookup table.
> Cheers,
> Haje
> "Christopher Lee" <cl@127.0.0.1> wrote in message
> news:20040610.093904.771151432.32286@buckley.atm.ox.ac.uk...
>> In article <ca72v6$qlb$1@aplcore.jhuapl.edu>, "Haje Korth"
>> <haje.korth@jhuapl.edu> wrote:
>>
>>> Good morning all,
>>> I am working on a coordinate transformation for a map and I have a
>>> simple problem. My mind is alreay blocked early in the morning and I
>>> could use some input: I have an rgb image of dimensions [3,1440,
>>> 720]. I need to rearranged the pixel in the image according to a
>>> lookup table of dimension [2,1440,360], which contains the column and
>>> row of the new pixel assigned to a location. Is there a magic way to
>>> do this without looping through each pixel in IDL?
>>> Thanks for helping,
>>> Haje
>>>
Ok, so you have two vectors of numbers, each one 1440*720 numbers long..
cx=fltarr(1440,720) ; Just setting the scene :)
cy=fltarr(1440,720)
;these map the value at source[cx[i,j],cy[i,j]] to
dest[i,j], which I think is what your doing.
source=fltarr(3,1440,720)
dest=fltarr(3, 1440,720)
dest[0,*,*]=source[replicate(0,1440,720),cx,cy]
etc.
;which, I think does what you want, it certainly manages the one-to-one
mapping find(i.e. the same coordinates). The replicate line is so that
IDL doesn't take a rectangle of the data, it's probably not absolutely
necessary here...but..
if you want to do all 3 channels in one go, and who wouldn't :)
nx=1440
ny=720
dest=source[ rebin(reform([0,1,2], [3,1,1]),[nx, ny]),
rebin(reform(cx,[1,nx,ny]), [3, nx, ny]),
rebin(reform(cy,[1,nx.ny]), [3,nx,ny])
]
I think that works, again, it mapped one-to-one ok.
Chris.
|
|
|