I want to segment image of size M x N into overlapped blocks with size k x k to generate (M-k+1) x (N-k+1) blocks. I have to find mean and variance of all the extracted/segmented blocks.
its not only segmentation, it include operations(mean and variance) on blocks within loop, my primary concern is to improve computational efficiency.
I have done the following coding in MATLAB:
A=imread('lena.jpg');
[M N]=size(A)
N=N/3
n=16;
m=16;
bl_mean=[];
bl_variance=[];
for i=1:M-m
for j=1:N-n
%[ii,jj]=ndgrid(n,m);
bl=A(i:(i+m-1),j:(j+n-1));
[bl_mean]=[bl_mean mean(mean(bl))];
[bl_variance]=[bl_variance var(var(double(bl)))];
B=sort(bl_mean);
B1=sort(bl_variance);
end
end
It was working fine for smaller image but for bigger image it keeps on processing for a long long time.
Any alternate or right way to find blocks in quick manner?