title: improving code efficiency: standard deviation on sliding windows
body: <p>I am trying to improve function which calculate for each pixel of an image the standard deviation of the pixels located in the neighborhood of the pixel. My function uses two embedded loops to run accross the matrix, and it is the bottleneck of my programme. I guess there is likely a way to improve it by getting rid of the loops thanks to numpy, but I don't know how to proceed.
  Any advice are welcome!</p>
  
  <p>regards</p>
  
  <pre><code>def sliding_std_dev(image_original,radius=5) :
      height, width = image_original.shape
      result = np.zeros_like(image_original) # initialize the output matrix
      hgt = range(radius,height-radius)
      wdt = range(radius,width-radius)
      for i in hgt:
          for j in wdt:
              result[i,j] = np.std(image_original[i-radius:i+radius,j-radius:j+radius])
      return result
  </code></pre>