|
Re: newbie: sub-array extraction [message #45808 is a reply to message #45800] |
Fri, 14 October 2005 09:20   |
Dick Jackson
Messages: 347 Registered: August 1998
|
Senior Member |
|
|
Another tip for the self-announced newbie: in Online Help under Contents,
find:
Programmer's Guides
Building IDL Applications
Application Programming
Writing Efficient IDL Programs
Lots of good stuff for the new IDL user.
Cheers,
-Dick
"Dick Jackson" <dick@d-jackson.com> wrote in message
news:WjG3f.179148$1i.83985@pd7tw2no...
> Hi Ben,
>
> "Ben Rogers" <ben.jordanrogers@gmail.com> wrote in message
> news:1129254169.767522.77270@g43g2000cwa.googlegroups.com...
>> [...] I am looking to extract a 5x5 array around a central pixel to
>> calculate some background statistics. Is this something best
>> acomplished with for loops or is there an idl function that does
>> something similar already?
>
> Certainly. The section in Online Help that you might want is "subscripts",
> but here's an example for you.
>
> nX = 10
> nY = 10
> array = BIndGen(nX, nY)
>
> pixX = 4
> pixY = 6
>
> subArray = array[pixX-2:pixX+2, pixY-2:pixY+2]
> Print, subArray
>
> ... and I get:
>
> 42 43 44 45 46
>
> 52 53 54 55 56
>
> 62 63 64 65 66
>
> 72 73 74 75 76
>
> 82 83 84 85 86
>
> To be more careful, truncating the array if the pixel[X|Y] is too close to
> the edge:
>
> pixX = 1
> pixY = 9
>
> subArray = array[(pixX-2)>0:(pixX+2)<(nX-1), (pixY-2)>0:(pixY+2)<(nY-1)]
> Print, subArray
>
> ... and I get:
>
> 70 71 72 73
>
> 80 81 82 83
>
> 90 91 92 93
>
> Hope this helps!
>
> Cheers,
> --
> -Dick
>
> Dick Jackson / dick@d-jackson.com
> D-Jackson Software Consulting / http://www.d-jackson.com
> Calgary, Alberta, Canada / +1-403-242-7398 / Fax: 241-7392
>
|
|
|
Re: newbie: sub-array extraction [message #45813 is a reply to message #45808] |
Thu, 13 October 2005 21:17   |
Dick Jackson
Messages: 347 Registered: August 1998
|
Senior Member |
|
|
Hi Ben,
"Ben Rogers" <ben.jordanrogers@gmail.com> wrote in message
news:1129254169.767522.77270@g43g2000cwa.googlegroups.com...
> [...] I am looking to extract a 5x5 array around a central pixel to
> calculate some background statistics. Is this something best
> acomplished with for loops or is there an idl function that does
> something similar already?
Certainly. The section in Online Help that you might want is "subscripts",
but here's an example for you.
nX = 10
nY = 10
array = BIndGen(nX, nY)
pixX = 4
pixY = 6
subArray = array[pixX-2:pixX+2, pixY-2:pixY+2]
Print, subArray
... and I get:
42 43 44 45 46
52 53 54 55 56
62 63 64 65 66
72 73 74 75 76
82 83 84 85 86
To be more careful, truncating the array if the pixel[X|Y] is too close to
the edge:
pixX = 1
pixY = 9
subArray = array[(pixX-2)>0:(pixX+2)<(nX-1), (pixY-2)>0:(pixY+2)<(nY-1)]
Print, subArray
... and I get:
70 71 72 73
80 81 82 83
90 91 92 93
Hope this helps!
Cheers,
--
-Dick
Dick Jackson / dick@d-jackson.com
D-Jackson Software Consulting / http://www.d-jackson.com
Calgary, Alberta, Canada / +1-403-242-7398 / Fax: 241-7392
|
|
|
|