MATLAB: Can anybody please help me to do the following

non-overlapping sub-blocks of nxn pixels

Divide the image being segmented into small non-overlapping sub-blocks of nxn pixels,each sub-block constituting a vector with nxn elements and each element corresponding to a pixel of the sub-block.

Best Answer

You can use mat2cell to divide a matrix into submatrices:
img = uint8(randi([0 255], 206, 100, 3)); %for example

n = 10; %for example
rowdist = n * ones(1, ceil(size(img, 1) / n));
rowdist(end) = size(img, 1) - sum(rowdist(1:end-1)); %in case n is not a divisor of the image height
coldist = n * ones(1, ceil(size(img, 2) / n));
coldist(end) = size(img, 2) - sum(coldist(1:end-1)); %in case n is not a divisor of the image width
subimgs = mat2cell(rowdist, coldist, size(img, 3))
To convert the cell array of matrices to a cell array of vectors:
subimgv = cellfun(@(m) m(:), subimgs, 'UniformOutput', false)