Q:

fast computation of histogram on a grid

I have a greyscale 200x200 image and I would like to compute the histogram of the intensity for each 8x8 window in the image. How can I compute that fast? I use for loops now but it is so slow. My current code looks like:
I = imread('image.jpg');
for i=1:8:height-7
    for j=1:8:width-7
       patch = I(i:i+7,j:j+7);
       % compute histogram for the patch
    end
end

A:

If you have the Image Processing Toolbox you can use the function blockproc which is a compiled and general version of your loop. Just define the callback function to be your histogram calculation.
B = blockproc(I, [8 8], @myhistfun)

