高斯平滑python中的图像 [英] Gaussian Smoothing an image in python

查看:108
本文介绍了高斯平滑python中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

也许是这样的事情?

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()

(原始图片取自此处)

这篇关于高斯平滑python中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆