MATLAB: Easily sub dividing image into blocks

mat2cell

this is my programme
[m n]=size(I);_(example image size is 256*256)_ c=mat2cell(I,[4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4],[4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4]); this is difficult and i want to sub divide the any image into (m/4)*(n/4) blocks.how can i do this easily?

Best Answer

im=rand(256);
[n,m]=size(im);
p=4
aa=1:p:n
bb=1:p:m
[ii,jj]=ndgrid(aa,bb)
out=arrayfun(@(x,y) im(x:x+p-1,y:y+p-1),ii,jj,'un',0)
Related Question