MATLAB: I’ve divided the image into non-overlapping blocks and i want to calculate the mean of every block…

meanstoring values of mean in an array.

after calculating the mean i;ve to store it in array corresponding to their block number
plz tell me how to do?
Mean=[];
for row = 1 : blockSizeR : rows
for col = 1 : blockSizeC : columns
row1 = row;
row2 = row1 + blockSizeR - 1;
row2 = min(rows, row2);
col1 = col;
col2 = col1 + blockSizeC - 1;
col2 = min(columns, col2);
oneBlock = grayImage(row1:row2, col1:col2);
m=mean(mean(oneBlock));
M=m;
Mean=[Mean;M];
disp(Mean);
end
end
the above code shows only the mean value… but i want that it also shows the block number corresponding to the mean value…
plz rectify or modify the above code in order to do so.

Best Answer

Not sure how you want to define block number but how about:
blockNumber = 1;
for row = 1 : blockSizeR : rows
for col = 1 : blockSizeC : columns
row1 = row;
row2 = row1 + blockSizeR - 1;
row2 = min(rows, row2);
col1 = col;
col2 = col1 + blockSizeC - 1;
col2 = min(columns, col2);
oneBlock = grayImage(row1:row2, col1:col2);
Mean(blockNumber) = mean2(oneBlock);
fprintf('The mean for block #%d = $f', ...
blockNumber, Mean(blockNumber));
blockNumber = blockNumber + 1;
end
end