Let us consider an image Y of size 512x512.
The code below serves to segment the image Y into blocks where each block take the size 8x8.
Matlab Code:
Try using mat2cell
to break the image up into blocks:
bsX = 10; bsY = 10;
[m,n] = size(Y);
numFullBlocksX = floor(n/bsX); numFullBlocksY = floor(m/bsY);
xBlocks = [repmat(bsX,numFullBlocksX,1); mod(n,bsX)*ones(mod(n,bsX)>0)];
yBlocks = [repmat(bsY,numFullBlocksY,1); mod(m,bsY)*ones(mod(m,bsY)>0)];
blockCell = mat2cell(Y,yBlocks,xBlocks)
To instead go from number of blocks to block size, lead with these two lines instead of bsX = 10; bsY = 10;
:
numBlocksX = 10; numBlocksY = 10;
bsX = ceil(n/numBlocksX); bsY = ceil(m/numBlocksY);