i've divided the image into non-overlapping blocks and i want to calculate the mean of every block...
Show older comments
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.
Accepted Answer
More Answers (2)
Abbas Cheddad
on 14 Feb 2013
Hi there,
You could do the following:
%%%%%%%%%%%%%
fun = @(block_struct) mean2(block_struct.data);
I2 = blockproc(A,[8 8],fun);
Block_Mean(:,1)=reshape(I2,[1 size(I2,1)*size(I2,2)]);
Block_Mean(:,2)=1:length(Block_Mean);
%%%%%%%%%%%%%%
Where "A" denotes your image and [8 8] is the size of the block of your choice. This will result in "Block_Mean" which holds the mean intensity and the corresponding block number.
2 Comments
angel
on 14 Feb 2013
Abbas Cheddad
on 14 Feb 2013
Block_proc returns a single image with the same size as "A" if you use the documented code as in:
fun = @(block_struct) ...
mean2(block_struct.data) * ones(size(block_struct.data));
But in the code I have given you, each pixel in "I2" corresponds to the mean of a single block.
Anyhow, since what you have in hand works for you then happy days!
Jan
on 14 Feb 2013
R = BlockMean(img, blockSizeR, blockSizeC);
3 Comments
angel
on 14 Feb 2013
Walter Roberson
on 15 Feb 2013
You need to download and install that code in order to have a BlockMean routine.
angel
on 15 Feb 2013
Categories
Find more on Neighborhood and Block Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!