Re: make a vector from all pixels in a moving window [message #74526] |
Sat, 22 January 2011 16:28 |
envi35@yahoo.ca
Messages: 48 Registered: March 2005
|
Member |
|
|
On Jan 22, 6:59 pm, Robin Wilson <ro...@rtwilson.com> wrote:
> Hi Jenny,
>
> I use the function below to do this for me. It might not be the most
> efficient way of doing it (my IDL code is often lacking in terms of
> efficiency), but it works:
>
> FUNCTION GET_LOCAL_SUBSET, n, x, y, arr
> ; This gets the local n x n window around the given x and y values
> ; It will repeat edge values as needed to provide the correctly sized
> ; return array
> ;
> ; Altered fromhttp://michaelgalloy.com/2006/10/10/local
> ; grid-points.html (Original Author: Michael Galloy)
> ;
> ; Calculate the offsets
> offsets = lindgen(n) - (n - 1) / 2
>
> ; Calculate the offsets from the given x and y values
> xoffsets = reform(rebin(offsets, n, n), n^2)
> yoffsets = reform(rebin(offsets, n^2), n^2)
>
> return, reform(arr[x + xoffsets, y + yoffsets],n,n)
> END
>
> See Michael's blog post (linked in the comments above) for more
> information on how it works.
>
> Hope this helps,
>
> Robin
This is just what I need! Thanks! Robin
|
|
|
Re: make a vector from all pixels in a moving window [message #74527 is a reply to message #74526] |
Sat, 22 January 2011 15:59  |
Robin Wilson
Messages: 40 Registered: August 2010
|
Member |
|
|
Hi Jenny,
I use the function below to do this for me. It might not be the most
efficient way of doing it (my IDL code is often lacking in terms of
efficiency), but it works:
FUNCTION GET_LOCAL_SUBSET, n, x, y, arr
; This gets the local n x n window around the given x and y values
; It will repeat edge values as needed to provide the correctly sized
; return array
;
; Altered from http://michaelgalloy.com/2006/10/10/local
; grid-points.html (Original Author: Michael Galloy)
;
; Calculate the offsets
offsets = lindgen(n) - (n - 1) / 2
; Calculate the offsets from the given x and y values
xoffsets = reform(rebin(offsets, n, n), n^2)
yoffsets = reform(rebin(offsets, n^2), n^2)
return, reform(arr[x + xoffsets, y + yoffsets],n,n)
END
See Michael's blog post (linked in the comments above) for more
information on how it works.
Hope this helps,
Robin
|
|
|