I have a 3d matrix (3x3x3)
, and I need to extract 3d patches (2x2x2)
and transform them in vectors.
In 2d, simply:
I=randi(5,3,3);
2d_patches=im2col(I,[2 2],'sliding');
What about 3d?
I=randi(5,3,3,3);
3d_patches= ???
im2col just works in 2d. In 3d I should recombine the vectors 1
and 7
, 2
and 8
, ...
Is there any fast function for this task?
Here is the other direction: (It is pretty slow and there is definitely a faster way)
Remember that MATLAB uses col major.
I do not believe that there is any built-in way to do this. If you need it to be fast, it should be fairly simple to write your own mex-function in c and call it from Matlab.
Here is my (quick and dirty) solution:
im3col.c:
Compile:
Test:
hi guys what about this solution. To obtain 3x3x3 ROIs from I suggest :