Gaussian Smoothing an image in python

Jenn picture Jenn · Jul 11, 2013 · Viewed 29.6k times · Source

I am very new to programming in python, and im still trying to figure everything out, but I have a problem trying to gaussian smooth or convolve an image. This is probably an easy fix, but I've spent so much time trying to figure it out im starting to go crazy. I have a 3d .fits file of a group of galaxies and have cut out a certain one and saved it to a png with aplpy. Basically, it needs to be smoothed as a gaussian to a larger beam size (i.e. make the whole thing larger by expanding out the FWHM but dimming the output). I know there are things like scipy.ndimage.convolve and a similar function in numpy that I can use, but im having a hard time translating it into something usefull. If anyone can give me a hand with this and point me in the right direction it would be a huge help.

Answer

Jaime picture Jaime · Jul 11, 2013

Something like this perhaps?

import numpy as np
import scipy.ndimage as ndimage
import matplotlib.pyplot as plt

img = ndimage.imread('galaxies.png')
plt.imshow(img, interpolation='nearest')
plt.show()
# Note the 0 sigma for the last axis, we don't wan't to blurr the color planes together!
img = ndimage.gaussian_filter(img, sigma=(5, 5, 0), order=0)
plt.imshow(img, interpolation='nearest')
plt.show()

enter image description here enter image description here

(Original image taken from here)