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.
Asked
Active
Viewed 3.9k times
17
-
have you tried OpenCV (opencv)[http://opencv.willowgarage.com/documentation/python/imgproc_image_filtering.html] – PepperoniPizza Jul 11 '13 at 14:38
-
I tried the link but it didn't work. – Jenn Jul 11 '13 at 19:05
-
yeah sorry, there was a typo, try it now: http://opencv.willowgarage.com/documentation/python/imgproc_image_filtering.html – PepperoniPizza Jul 11 '13 at 21:06
1 Answers
30
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()
(Original image taken from here)

Jaime
- 65,696
- 17
- 124
- 159
-
That worked really well, thank you! Do you know if this is possible to do with the .fits file itself? Then I could do this with the original file without converting it to a png. – Jenn Jul 11 '13 at 19:04
-
1You will need a specific library to read that format in. I quick google search led me [here](http://www.astropy.org/). I don't have `astropy` installed on my system, but it appears to be [well documented](https://astropy.readthedocs.org/en/v0.2.3/io/fits/index.html). – Jaime Jul 11 '13 at 19:31
-
just use pyfits? import pyfits A=pyfits.getdata(filename) than A should be the numpy.ndarray with your data in it, and than do the ndimage filter on it – usethedeathstar Jul 12 '13 at 06:44
-
1@Jenn If this answer solved your problem please accept it (the big gray check box on the left). – tacaswell Aug 04 '13 at 05:55