高斯平滑python中的图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17595912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 08:37:52  来源:igfitidea点击:

Gaussian Smoothing an image in python

pythonnumpyscipygaussiansmoothing

提问by Jenn

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.

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

回答by Jaime

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 hereenter image description here

在此处输入图片说明在此处输入图片说明

(Original image taken from here)

(原图取自这里