title: Calculating variance image python
body: <p>Is there an easy way to calculate a running variance filter on an image using Python/NumPy/Scipy? By running variance image I mean the result of calculating sum((I - mean(I))^2)/nPixels for each sub-window I in the image.</p>
  
  <p>Since the images are quite large (12000x12000 pixels), I want to avoid the overhead of converting the arrays between formats just to be able to use a different library and then convert back.</p>
  
  <p>I guess I could do this manually by finding the mean using something like</p>
  
  <pre><code>kernel = np.ones((winSize, winSize))/winSize**2
  image_mean = scipy.ndimage.convolve(image, kernel)
  diff = (image - image_mean)**2
  # Calculate sum over winSize*winSize sub-images
  # Subsample result
  </code></pre>
  
  <p>but it would be much nicer to have something like the stdfilt-function from Matlab.</p>
  
  <p>Can anyone point me in the direction of a library that has this functionality AND supports numpy arrays, or hint at/provide a way to do this in NumPy/SciPy?</p>