MATLAB: I know how to divide the 256×256 image into 16×16 blocks using mat2cell. Now I want to access those 16×16 blocks successively to further divide them into 4×4 blocks.

image processing

I'm able to do this further division by taking one 16×16 block at a time (first using cell2mat and then again using mat2cell this time with parameter 4), but I want to do it using some 'for' loop, or anything for that matter in which I wouldn't have to access each 16×16 blocks individually.
Any idea how I can achieve that?
Thank you.

Best Answer

Read about cellfun(). Try something like this
img = rand(256);
C1 = mat2cell(img, 16*ones(16,1), 16*ones(16,1));
C2 = cellfun(@(x) mat2cell(x, 4*ones(4,1), 4*ones(4,1)), C1, 'UniformOutput', 0);