Question

I want to make a non-overlapping 3D matrix in scilab, and loop through it with a cube of NxNxN size assigning the average value of the voxels in the cube to the center voxel.

Go to Page 2 to see exactly what I need. https://drive.google.com/file/d/0B5wCiQEnPJYZdGxCcmRBc0NHNGc/edit?usp=sharing

Thank you so much in advance.

P.S. Don't worry about the invalid averaging volume problem. The Matrix can just be 100x100x100 or similar.

Was it helpful?

Solution

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 )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top