-2

I have a 4D image of size 60 x 80 x 12 x 350, i.e. it is a 3D image where each voxel has a time series (of 350).

Now I want to use mat2cell to divide the 3D image into cubes of dimension k*k*k. Each voxel in the cube is a vector of size 350 (the time series).

I think I could do it with mat2cell but I don't know how exactly. Each cell should contain in the end a 3D block of the image where each voxel of the block is a vector of size 350.

Autonomous
  • 8,935
  • 1
  • 38
  • 77
machinery
  • 5,972
  • 12
  • 67
  • 118
  • 1
    What is `k` here? Also, can you explain clearly what the resulting cell should contain? – Autonomous Jun 02 '15 at 22:54
  • 1
    what happens it `L x W x C`(C=channels) is not evenly divisible by `k x k x k`? for instance using your dimenstions ` 60 x 80 x 12 x 350` and `k=10` you can make voxels for `60 x 80 x 10` but what happens for the last 2 channels? – andrew Jun 02 '15 at 23:02
  • @andrew I took care of that in my answer and did a cut off final cell. I think it's cleaner than padding. – user1543042 Jun 02 '15 at 23:10

1 Answers1

1

Assuming your 4D matrix is called M. You need to have vectors whose elements sum to size(M, i) where i = 1:4. Assuming k has some value, I tried both 4 (because it's a common factor of the sizes you specified) and 3 (because it's not).

k = 3;
MPrime = mat2cell(M, ...
    [k*ones(1, floor(size(M,1)/k)), mod(size(M,1), k)], ...
    [k*ones(1, floor(size(M,2)/k)), mod(size(M,2), k)], ...
    [k*ones(1, floor(size(M,3)/k)), mod(size(M,3), k)], ...
    ones(1, size(M,4)));
user1543042
  • 3,422
  • 1
  • 17
  • 31