For each voxel in a 3D logical or numeric array, sum the values of the six neighboring voxels.
sum_neighbors_vol(arr, pad = 0)An array with the same dimensions as arr. Each voxel value
will be the sum across the immediate neighbors. If arr was a logical
array, this value will be between 0 and 6.
The 3D array.
In order to compute the sum, the array is temporarily padded along
each edge with the value of pad. 0 (default) will mean that
edge voxels reflect the sum of 3-5 neighbors whereas non-edge voxels reflect
the sum of 6 neighbors. An alternative is to use a value of NA so
that edge voxels are NA-valued because they did not have a complete
set of six neighbors. Perhaps another option is to use mean(arr).
Diagonal voxels are not considered adjacent, i.e. the voxel at (0,0,0) is not adjacent to the voxels at (1,1,0) or (1,1,1), although it is adjacent to (1,0,0).