function [ patches ] = get_patches(data, layer_params)
%GET_PATCHES Summary of this function goes here
%   Detailed explanation goes here
%
% Austin Myers July 2013
% Adapted from code by Liefeng Bo

patch_sz = layer_params.patch_sz;

if size(data,3) > 1
   patches = im2colstep(data, [patch_sz patch_sz size(data,3)], [1 1 1]);
else
   patches = im2colstep(data, [patch_sz patch_sz], [1 1]);
end

if layer_params.remove_DC
    patches = remove_dc(patches, 'columns');
end        

% Normalization (L2)
if layer_params.L2_normalize
    threshold = 0.01;
    %L2 normalization
    patches = bsxfun(@rdivide, patches,  max(sqrt(sum(patches.^2, 1)), threshold));
end

end
