docs: def variance_transform(img, sigma, mask=None):
      '''Calculate a weighted variance of the image
  
      This function caluclates the variance of an image, weighting the
      local contributions by a Gaussian.
  
      img - image to be transformed
      sigma - standard deviation of the Gaussian
      mask - mask of relevant pixels in the image
      '''
      if mask is None:
          mask = np.ones(img.shape, bool)
      else:
          img = img.copy()
          img[~mask] = 0
      #
      # This is the Gaussian of the mask... so we can normalize for
      # pixels near the edge of the mask
      #
      gmask = scind.gaussian_filter(mask.astype(float), sigma,
                                    mode = 'constant')
      img_mean = scind.gaussian_filter(img, sigma,
                                       mode = 'constant') / gmask
      img_squared = scind.gaussian_filter(img ** 2, sigma,
                                          mode = 'constant') / gmask
      var = img_squared - img_mean ** 2
      return var