# How split an image into four parts?

7 views (last 30 days)
Bajdar Nouredine on 3 Jan 2023
Moved: Matt J on 6 Jan 2023
I have 2x10 cell array each cell contains 224x896 double, I want to split each image inside the cells to 224x224

Voss on 3 Jan 2023
Edited: Voss on 3 Jan 2023
% since I don't have your cell array, I make one up:
C = repmat({randi([0 255],224,896)},2,10)
C = 2×10 cell array
{224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double} {224×896 double}
% split each matrix in C into 4:
C_new = cellfun(@(x)mat2cell(x,224,224*ones(1,4)),C,'UniformOutput',false)
C_new = 2×10 cell array
{1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell} {1×4 cell}
% each cell of C_new contains a 1x4 cell array containing the 4 224x224 matrices:
C_new{1,1}
ans = 1×4 cell array
{224×224 double} {224×224 double} {224×224 double} {224×224 double}
C_new{2,1}
ans = 1×4 cell array
{224×224 double} {224×224 double} {224×224 double} {224×224 double}
% etc.
Bajdar Nouredine on 6 Jan 2023
Moved: Matt J on 6 Jan 2023

Matt J on 6 Jan 2023
Edited: Matt J on 6 Jan 2023
C(1:2,1:10)={rand(224,896)}; %hypothetical input
A= mat2tiles( cell2mat(C), [224,224]);
A=permute(reshape(A,2,4,10),[1,3,2]) %final result
A = 2×10×4 cell array
A(:,:,1) = {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} A(:,:,2) = {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} A(:,:,3) = {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} A(:,:,4) = {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double} {224×224 double}

### Categories

Find more on Feature Detection and Extraction in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!