如何使用Python在图像上添加具有真实高斯形状的高斯模糊
假设我有一个如下2D数组的图像:如何使用Python在图像上添加具有真实高斯形状的高斯模糊,python,gaussian,probability-distribution,ndimage,Python,Gaussian,Probability Distribution,Ndimage,假设我有一个如下2D数组的图像: img = np.array([ [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
img = np.array([
[0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0]])
我想对其应用高斯模糊,因此图像如下所示:
imgBlurred = np.array([
[0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
[0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
[0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
[0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
[0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
[0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
[0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
[0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1]])
基本上,我想要一个结果,其中高斯对于原始图像中的值来说非常厚,对于0.5的值来说更大
到目前为止,我的工作如下:
from scipy import ndimage
import numpy as np
#img is a numpy array
imgBlurred = ndimage.filters.gaussian_filter(img, sigma=0.7)
#Normalisation by maximal value, because the gaussian blur reduce the 1 to ~0.5
imgBlurred = imgBlurred/imgBlurred.max()
imgBlurred[imgBlurred > 1] = 1# In case of the maximal value was > 1
但这样做会使相同的图像变大,模糊图像变大0.5。
如果有人知道如何解决这个“问题”,我想有一些建议 你说的更大更厚是什么意思?根据每个像素的值,你想要不同的sigma吗?是的,它可以是sigma,但是在这里,像素已经定义好了,我正在寻找是否可以在我的图像上使用高斯滤波器,并获得px=0.5的«平坦»分布。是否可能使用相同的sigma?像素是否始终具有此模式,即以列为单位?然后你可以使用1d内核。不,这只是个例子,它们可以以不同的角度定向