title: Gaussian filter of 2d image with location dependant sigma in Python
body: <p>I am trying to implement in Python a Gaussian filter in which the kernel is 
  <a href="https://i.stack.imgur.com/Pk7VJ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Pk7VJ.jpg" alt="enter image description here"></a></p>
  
  <p>where  <code>f(x,y)</code> is some function of the coordinates. Is it possible somehow to trick <a href="http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.ndimage.filters.gaussian_filter.html" rel="nofollow noreferrer">scipy.ndimage.filters.gaussian_filter</a> to do the job?</p>
  
  <p>Eventually I will have to perform the following integration over space:</p>
  
  <p><a href="https://i.stack.imgur.com/UE0dZ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UE0dZ.jpg" alt="enter image description here"></a></p>
  
  <p>And so I get $\tilde G(x',y') $ as a coordinate dependent coefficient.</p>
  
  <p>Right now I am making it with tedious <code>for</code> loops:</p>
  
  <pre><code>def calc_g1(b,w,p):
      nx,ny = b.shape
      g1 = np.zeros_like(b)
      for i in np.arange(nx):
          for j in np.arange(ny):
              for ii in np.arange(nx):
                  for jj in np.arange(ny):
                      g = calc_kernel(b,p,i,j,ii,jj)
                      g[i,j]+=g*w[ii,jj]
      return g1
  
  
  def calc_kernel(b,w,i,j,ii,jj):
      dx,dy = p['dx'],p['dy']
      dist_x = dx*np.abs(ii-i)
      dist_y = dy*np.abs(jj-j)
      dist = dist_x**2 + dist_y**2
      f = (1.0 + p['eta']*b[i,j])**2
      return 1.0/(2.0*np.pi)*np.exp(-(dist)/(2.0*f))
  </code></pre>
  
  <p>** Can I do it somehow using Symbolic calculation using SymPy or Theano?</p>