MATLAB: How to divide an image 512×512 into 4×4 overlapping blocks.

image processingImage Processing Toolbox

I have a lena image of 512×512. I want divide the image into 4×4 overlapping blocks, for which i wrote the below code. And i also have to find the no. of 4×4 overlapping blocks. Here I have set a counter to check the no.of 4×4 overlaping blocks. Am i doing it correctly? Please Help.Thanks
[e,f] = size(outImg);
counter=0
for i = 1:e-3
for j = 1:f-3
I = double(outImg((i:i+3),(j:j+3)));
counter=counter+1;
end
end

Best Answer

Why overlapping? What are you doing with the badly-named I? Nothing. If you want non-overlapping sub-images extracted, you can use indexing or mat2cell. These techniques are shown in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_split_an_image_into_non-overlapping_blocks.3F
If you want overlapping you can use imfilter(), conv2(), or even blockproc(), but you have to specify some operation, which you haven't done yet.