Actually, Radha, you should not need a FOR loop at all. What you want to do is what is called a convolution, and it is performed on whole arrays in a one line call to CONVOL in IDL. Here is an example, whose behavior is easy to observe:
; Make an example 8x8 array of easy-to-add random numbers
IDL> seed = 1L
IDL> data = float(floor(randomu(seed, 8, 8) * 5))
IDL> print, data, FORMAT='(8D6.1)'
2.0 0.0 3.0 2.0 4.0 1.0 3.0 0.0
3.0 3.0 1.0 3.0 4.0 2.0 3.0 1.0
1.0 3.0 3.0 4.0 0.0 1.0 4.0 1.0
2.0 1.0 1.0 2.0 4.0 4.0 0.0 4.0
3.0 3.0 0.0 1.0 2.0 4.0 4.0 4.0
1.0 3.0 0.0 1.0 1.0 4.0 1.0 3.0
0.0 3.0 2.0 4.0 3.0 1.0 0.0 2.0
2.0 0.0 2.0 2.0 2.0 1.0 4.0 3.0
IDL> kernel = fltarr(3, 3) + 1./9. ; This is a 3 x 3 matrix of weights with same value .111
IDL> print, convol(data, kernel), FORMAT='(8D6.2)'
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 2.11 2.44 2.67 2.33 2.44 1.78 0.00
0.00 2.00 2.33 2.44 2.67 2.44 2.22 0.00
0.00 1.89 2.00 1.89 2.44 2.56 2.89 0.00
0.00 1.56 1.33 1.33 2.56 2.67 3.11 0.00
0.00 1.67 1.89 1.56 2.33 2.22 2.56 0.00
0.00 1.44 1.89 1.89 2.11 1.89 2.11 0.00
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
There are keywords to CONVOL that give you different choices about how the edge values of the output should be calculated ... and/or you can always merge the CONVOL output with the edges of the original data if you like.
James Jones
ITT Technical Support
|