Dense 3D patch extraction from video (stride allowed)

Version 1.3.0.0 (2 KB) by Yu
The code can extract columns of 3D patches from a 3D matrix (i.e. video). Stride is supported.
318 Downloads
Updated 26 Feb 2014

View License

Similar to im2col, the video2col2 can extract columns of 3D patches from a 3D matrix, e.g. video. Spatial and temporal step sizes can also be applied.
Usage:
B=video2col2(A,[PATCH_SIZE], [STEP_SIZE]);
A: 3D matrix, e.g. a video.
PATCH_SIZE: size of a patch, e.g., [2,2,2].
STEP_SIZE: the stride in each dimension, e.g. [2,3,4].

The video2col2 will extract a floor[(M_r-w_r)/s_r+1] * floor[(M_c-w_c)/s_c+1] * floor[(M_t-w_t)/s_t+1] 3D patches B, where a video is of size M_r*M_c*M_t and each patch is of size w_r*w_c*w_t. The step size is [s_r, s_c, s_t] alone the spatial and temporal axis.

Each column in B is a patch.

Example:
A=rand(100,90,80);
B=video2col2(A,[3,4,5],[2,3,4]);

In this case, a video A is of size 100*90*80, i.e., the video has 80 frames and the number of rows is 100.
Patch size is 3*4*5 and the step size is 2*3*4. Then B will be a 60*26999 matrix, where 60 is the size of a patch (60=3*4*5) and 26999 is the number of extracted patches.

Tested on Mac and Windows with Matlab R2013b. You need to compile it using
mex -O video2col2.c

Cite As

Yu (2024). Dense 3D patch extraction from video (stride allowed) (https://www.mathworks.com/matlabcentral/fileexchange/45417-dense-3d-patch-extraction-from-video-stride-allowed), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2013b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.3.0.0

Description updated.

1.2.0.0

Variable declaration problem fixed for Windows.

1.1.0.0

Add more description.

1.0.0.0