[SciPy-user] gaussian smoothing

Alok Singhal as8ca@virginia....
Tue Nov 6 12:06:44 CST 2007


Hi,

On 06/11/07: 09:29, Marc Beck wrote:
> 
>    I am a graduate assistant at the Space Science Center at Morehead
>    State University. I am currently writing a program to convert raw data
>    from our 21m antenna into a *.FITS image using numpy and scipy. I need
>    to convolve the pixels of my image. I have three arrays: one for the
>    x- coordinate, one for the y- coordinate and one for the brightness of
>    the pixel. I need to feed those three arrays into a function to
>    convolve the pixels and I need to get the same three arrays out with
>    the new values, or the rest of the program does not work.

Here's one way to do it:

Assuming the brightness array is a two-dimensional array with shape
(nx, ny), where nx = len(x), ny = len(y); you can do something like:

# <brightness> is the two-dimensional array of brightness values,
# <sigma_x>, <sigma_y> are the sigma values for the two gaussians
# in x and y respectively.  NOTE: the sigma values are in terms of array
# indices, and not in the units of  x and y values.
#
# So, if x and y are uniformly spaced:
#
#    sigma_x = sigma_x / (x[1]-x[0])
#    sigma_y = sigma_y / (y[1]-y[0])
#
# The output image is in the array <out> in this example
from scipy.ndimage import gaussian_filter
gaussian_filter(brightness, sigma=(sigma_x, sigma_y), output=out, mode='constant', cval=0.0)

-Alok

-- 
Alok Singhal                               *   *          
Graduate Student, dept. of Astronomy   *           *     *
University of Virginia                                    
http://www.astro.virginia.edu/~as8ca/              *    * 


More information about the SciPy-user mailing list