A[3[3]1 2 3 B[3][3] _ _ _

4 5 6 _ _ _

7 8 9 _ _ _

-5 has neighbours 1,2,3,4,6,7,8,9. and need to find the average of them and replace it to position B[1][1].

-1 has 2,4,5. and need to find average of them and replace it to position B[0][0].

this is wat i have atm.

for(r=1; r<h-1; r++){ for(c=1; c<w-1; c++){ tot=0; average=0; howmany=9; tot=cpyimage[r-1][c-1].gray_level+cpyimage[r-1][c].gray_level+cpyimage[r-1][c+1].gray_level+cpyimage[r][c-1].gray_level+cpyimage[r][c].gray_level+cpyimage[r] [c+1].gray_level+cpyimage[r+1][c-1].gray_level+cpyimage[r+1][c].gray_level+cpyimage[r+1][c+1].gray_level; average=tot/howmany; myimage[r][c].gray_level=average; } }

but it misses out the edges. im having trouble averaging them because they have less than 8 neighbours , unlike the ones in the middle which have 8 neighbours. how do i o about doing this? can someone help point me in the right direction?