blockSizeR = 128;
blockSizeC = 128;
wholeBlockRows = floor(rows / blockSizeR);
wholeBlockCols = floor(columns / blockSizeC);
trailing_rows = rows - wholeBlockRows * blockSizeR;
trailing_cols = cols - wholeBlockCols * blockSizeC;
image3d_cell = mat2cell( YourImage, [blockSizeR * ones(1, wholeblockRows), trailing_rows], [blockSizeC * ones(1, wholeBlockCols), trailing_cols], size(YourImage, 3) );
Now image3d_cell will be a cell array, wholeBlockRows or wholeBlockRows+1 (if there are trailing rows), by wholeBlockCols or wholeBlockCols+1 (if there are trailing columns).
if trailing_rows == 0 && trailing_cols == 0
image3d = cat( ndims(YourImage)+1, image3d_cell{:} );
else
image3d = [];
warning('There were trailing rows or columns, could not form 3D image automatically');
end
Best Answer