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

Home » Public Forums » archive » Re: Array indexing problem: Appreciated
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
Re: Array indexing problem: Appreciated [message #37857] Thu, 29 January 2004 05:42
Ken Knapp is currently offline  Ken Knapp
Messages: 14
Registered: April 2003
Junior Member
My 2 cents-
I won't say I "enormously appreciate" it, but here is how I have found
it useful. Consider needing to calculate a spatial standard deviation
for an image. Rather than loop over the dimensions of the image, I loop
over the size of the standard deviation window. I use this array
notation so I don't have to worry about the calculations at the edges.
here's my code. If there is a simpler way to do this without the
"enormously appreciated" "feature" then let me know ;-)
-Ken


function spatstdev,input,n

s=size(input)
nx = s(1)
ny = s(2)

var = fltarr(nx+2*n,ny+2*n)
mask= intarr(nx+2*n,ny+2*n)
var(n:n+nx-1,n:n+ny-1) = input
mask(n:n+nx-1,n:n+ny-1) = 1

ii = lindgen(nx,ny)
i = (ii mod nx) + n
j = floor(ii / nx) + n
x2 = fltarr(nx+2*n,ny+2*n)
x = fltarr(nx+2*n,ny+2*n)
nn = fltarr(nx+2*n,ny+2*n)

for ii = -n,n do begin
for jj = -n,n do begin
x2 = x2 + var[i+ii,j+jj]^2
x = x + var[i+ii,j+jj]
nn = nn + mask[i+ii,j+jj]
endfor
endfor

std = sqrt((x2 - ((x^2)/nn)) / (nn-1))

return,std
end

--
***** to reply remove the _REMOVE_ *****

Ken Knapp Ken.Knapp@_REMOVE_noaa.gov
Remote Sensing and Applications Division
National Climatic Data Center
151 Patton Ave
Asheville, NC 28806
828-271-4339 (voice) 828-271-4328 (fax)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Resizing Oddity
Next Topic: Re: Resizing Oddity

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

Current Time: Wed Oct 08 18:38:33 PDT 2025

Total time taken to generate the page: 0.00506 seconds