Code covered by the BSD License  

Highlights from
Block Division using cell

image thumbnail
from Block Division using cell by Suraj Kamya
Using cell data type one can effectively breaks the 2D/3D data in to required no. of blocks.

[B]=blocks(image)
function [B]=blocks(image)
% blocks function divides the image in to 8*8 blocks
% and put all the blocks in to one varibale of cell data type.
% image - requires 2-D image as input
% B     - output having 8*8 blocks in one cell

m=imresize(image,[512,512]);
k=1; dr=0; dc=0;
% dr is to address 1:8 row every time for new block in x
% dc is to address 1:8 column every time for new block in x
% k is to change the no. of cell

for ii=1:8:512 % To address row -- 8X8 blocks of image
    for jj=1:8:512 % To address columns -- 8X8 blocks of image
        for i=ii:(ii+7) % To address rows of blocks
            dr=dr+1;
            for j=jj:(jj+7) % To address columns of block
                dc=dc+1;
                z(dr,dc)=m(i,j);
            end
            dc=0;
        end
        x{k}=z; k=k+1;
        z=[]; dr=0;
    end
end
B=x;

Contact us