1

I would like to calculate a Gaussian weighted standard deviation of a 2D array with Python, does anyone know how to do this? So basically apply a 2D Gaussian filter but instead of returning the convolution of each array element with the filter, I would like it to return the standard deviation of the Gaussian weighted values around some array element.

cheers, Tomas

Tomas
  • 503
  • 2
  • 7
  • 15

2 Answers2

1

There is a numpy function called std. Example

    x = np.random.uniform(0,5,(20,20))
    np.std(x)

And this will return the standard deviation of the 20x20 array. If you want a specific portion of the image you can use array splicing to accomplish this.

jfish003
  • 1,232
  • 8
  • 12
1

For a non weighted filter that returns the local standard deviation for 2D arrays, you could use,

scipy.ndimage.filters.generic_filter(image, function=np.std, size=(10, 10)) 

Unfortunately, I don't think there is a function to do what you want in standard scientific python modules. You would probably have to write your own implementation (see the general approach in this answer ).

rth
  • 10,680
  • 7
  • 53
  • 77
  • Thanks @rth, indeed a filter like that is what I am looking for, but then with a Gaussian weight. – Tomas Jul 18 '15 at 16:36