The problem you describe is different from the paper you posted. I followed your description, but split it up into multiple lines so you can easily adapt it to your requirements.
It is very similar to the MatLab answer somebody posted in your other question. I am not aware of anything similar to mat2cell
and cellfun
in SciLab as used in the other answer.
clear; clc
K = 100
N = 5
mid = floor(N/2)
volume = rand(K, K, K)
cubeCount = floor( K / N )
for x=0:cubeCount-1
for y=0:cubeCount-1
for z=0:cubeCount-1
// Get a cube of NxNxN size
cube = volume((1:N)+N*x, (1:N)+N*y, (1:N)+N*z);
//Calculate the average value of the voxels in the cube
avg = sum( cube ) / (N * N * N);
// Assign it to the center voxel
volume( N*x+mid+1, N*y+mid+1, N*z+mid+1 ) = avg
end
end
end
disp( volume )