If I have a 3D array how do I sum up the value given a boundary? : Let's say I have a 3D array such that

    int[][][] array = 
    {  { {1,   2,  3}, { 4,  5,  6}, { 7,  8,  9} },
       { {10, 11, 12}, {13, 14, 15}, {16, 17, 18} },
       { {19, 20, 21}, {22, 23, 24}, {25, 26, 27} } };


----------

Now the array is as follow

**First Image**

1 2 3

4 5 6

7 8 9

**Second Image**

10 11 12

13 14 15

16 17 18

**Third Image**

19 20 21

22 23 24

25 26 27

----------

I would like to sum up the value in the 3 X 3 matrix boundary and create a new array such that one example of summation of the top left corner is that

**First Example**

((1+2+4+5)+(10+11+13+14)+(19+20+22+23))/ 12 

The second example will be to take the centre value and compute the average

**Second Example**

((1+2+3+4+5+6+7+8+9)+(10+11+12+13+14+15+16+17+18)+(19+20+21+22+23+24+25+26+27))/ 27


where it will compute the average of all the values that are within a 3 by 3 square centred at the pixel.