function [ blocks ] = D35WQ8_im2block( im, block_size )
    
    BH = block_size(1);
    BW = block_size(2);
    [H, W, C] = size(im);
    Rows = floor(H/BH);
    Cols = floor(W/BW);
    
    blocks = zeros(Rows*Cols, BH, BW, C);
    for i=1:Rows
        for j=1:Cols
            blocks((j-1)*Rows+i, :, :, :) = im((i-1)*BW+1:i*BW, (j-1)*BH+1:j*BH, :);
        end
    end
    
    
    % Matlab, the only language where you have to think wether it worths 
    % using the built-in functions
%     xcell = mat2cell(img, repmat(BH,[1 Rows]), repmat(BW,[1 Cols]), C);
%     x3d = cat(4,xcell{:});
%     x3d = reshape(permute(x3d, [4, 3, 1, 2]), [], 3, BH, BW);
%     x3d = permute(x3d, [1, 3, 4, 2]);
end

