How to divide images from folder into 4x4 blocks
Show older comments
I want to divide all images in a folder into 4x4 blocks and then store the RGB information in a zeros matrix. A sample of what the images look like is attached. Does anyone know how to divide into these blocks and then store the information in the matrix.

3 Comments
Turlough Hughes
on 5 May 2021
"and then store the RGB information in a zeros matrix", can you expand on that. How exactly do the 4x4 pixel blocks relate to your new matrix?
Turlough Hughes
on 5 May 2021
Edited: Turlough Hughes
on 5 May 2021
Also, consider the blockproc function. This might be the way to go depending on what it is you're trying to do.
Petrus van Aswegen
on 5 May 2021
Accepted Answer
More Answers (1)
Jonas
on 5 May 2021
you could use mat2cell
A = rand(256,256,3); % your matrix here
N = 4*ones(1,64);
B = mat2cell(A,N,N,3);
adjusted from here
3 Comments
Petrus van Aswegen
on 5 May 2021
Jonas
on 5 May 2021
catch all files you are interested in eg by {dir('*.jpg').name} and loop through the file names and open them with imread()
Petrus van Aswegen
on 5 May 2021
Categories
Find more on Blocked Images 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!