i divided the image into nonoverlapping blocks. now i've to calculate the mean of evry block. how to calculate it? pease correct the code

1 view (last 30 days)
clc
close all
clear all
a=imread('cameraman.tif');
for i=1:8:size(a,1)
for j=1:8:size(a,2)
b=a((i:i+7),(j:j+7));
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=b;
Mean=[Mean;M];
disp(Mean);
end
end
end
end

Answers (1)

Matt J
Matt J on 25 Nov 2014
It will be more efficient to use sepblockfun ( Download ).
Mean=sepblockfun(grayImage,[8,8],@mean);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!