高斯平滑python中的图像

时间:2013-07-11 14:20:20

标签: python numpy scipy gaussian smoothing

我对python中的编程非常陌生,我仍然试图解决所有问题,但我在尝试高斯平滑或卷积图像方面遇到了问题。这可能是一个简单的解决方案,但我花了很多时间试图弄明白我开始变得疯狂。我有一组3d .fits文件中的一组星系,并删除了某个星系并将其保存到png with aplpy。基本上,它需要作为高斯光滑平滑到更大的光束尺寸(即通过扩展FWHM但使输出变暗来使整个事物更大)。我知道有些东西像scipy.ndimage.convolve和类似的numpy函数我可以使用,但我很难将它翻译成有用的东西。如果有人能够帮助我,并指出我正确的方向,那将是一个巨大的帮助。

1 个答案:

答案 0 :(得分:22)

或许这样的事情?

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

(原始图片取自here