Sliding Gabor Filter in python
Question: Taken from the gabor filter example from skimage calculating a gabor filter
for an image is easy:

    
    
    import numpy as np
    
    from scipy import ndimage as nd
    
    from skimage import data
    from skimage.util import img_as_float
    from skimage.filter import gabor_kernel
    
    brick = img_as_float(data.load('brick.png'))
    
    kernel = np.real(gabor_kernel(0.15, theta = 0.5 * np.pi,sigma_x=5, sigma_y=5))
    
    filtered = nd.convolve(brick, kernel, mode='reflect')
    
    mean = filtered.mean()
    variance = filtered.var()
    

brick is simply a numpy array. Suppose I have a 5000*5000 numpy array. What I
want to achieve is to generate two new 5000*5000 numpy arrays where the pixels
are the mean and var values of the gabor filter of the 15*15 window centered
on them.

Could anyone help me achieve this?

**EDIT**

¿Why did I get downvoted? Anyway, to clarify I show an example on how to
calculate a gabor filter on a single image. I would like to simply calculate a
gabor filter on small square subsets of a very large image (hence the sliding
window).


Answer: There no standard methods to do this (that I know of), but you can do it
yourself directly.

Each pixel in the convolution is the sum of the values of the shift gabor
filter times the image pixels. That is, each pixel in the convolution is
basically the **mean** to within a constant normalization factor, so
`filtered` is basically your mean.

The **variance** is a bit more difficult since that is the sum of the squares,
and of course, you need to calculate the sqaures before you calculate the
sums. But, you can do this easy enough by pre-squaring both the image and the
kernel, that is:

    
    
    N = kernel.shape[0]*kernel.shape[1]
    mean = nd.convolve(brick, kernel, mode='reflect')/N
    var = nd.convolve(brick*brick, kernel*kernel, mode='reflect')/N - mean*mean
    

