split 3 dimesnsional array into equal blocks along the first 2 dimensions
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
images is a cell array of 12 images. I want to split images into many rectangular blocks, with each of the 12 images stacked together. The following code achieves what I intend, but I hoping if someone could verify that this is the most efficient code that can be written. I am new to matlab and hence not ver confident.
xParts = 5; %divide rows into 5 parts.
yParts = 5; %divide columns into 5 parts.
mdImages = cat(3, images{:}); %convert cell array to 3 dimensional matrix
%get vector for: how to split the rows.
xSplit = repmat(floor(size(mdImages,1)/xParts), [1 xParts]);
xSplit(end) = xSplit(end) + mod(size(mdImages,1), xParts);
%get vector for: how to split the columns.
ySplit = repmat(floor(size(mdImages,2)/yParts), [1 yParts]);
ySplit(end) = ySplit(end) + mod(size(mdImages,2), yParts);
imgCells = mat2cell(mdImages, xSplit, ySplit, [size(mdImages, 3)]);
%convert each cell from 3 dimensional matrix to 2 dimensional.
sequences = cellfun(@(x) reshape(x, [], size(x, 3)), imgCells, 'UniformOutput', false);
0 comentarios
Respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!