这是一个关于高斯滤波器理论的问题,而不是具体的编码问题。
我有一个2D D.O.G
的实现。在python中过滤。我想在不同的空间频带上制作噪声掩模,例如1-5 cpd
。为此,我首先创建一个白噪声阵列然后我将添加DOG滤波器以带通滤波不同空间范围内的噪声。
有没有办法从每个贡献高斯滤波器的参数中明确定义高斯差分滤波器的带宽?
( BONUS Q':是否可以对这些高斯中的每一个进行傅里叶变换,然后将其视为各个带宽的频谱,然后是DOG带宽?单位是什么?在傅立叶空间?我怎么能把它转换成空间频率范围?抱歉很多问题)
非常感谢,
注意:我使用conv2
函数而不是内置的python 2d卷积来提高速度(其他应用程序)。
import numpy as np
import math
import matplotlib.pylab as plt
from scipy.ndimage.filters import convolve
def Gaussian2D(GCenter, Gamp, Ggamma,Gconst): #new_theta > 0.4:
"""
Produces a 2D Gaussian pulse *EDITED BY WMBM
Parameters
----------
GCenter : int
Centre point of Gaussian pulse
Gamp : int
Amplitude of Gaussian pulse
Ggamma : int
FWHM of Gaussian pulse
Gconst : float
Unkown parameter of density function
Returns
----------
GKernel : array_like
Gaussian kernel
"""
new_theta = math.sqrt(Gconst**-1)*Ggamma
SizeHalf = np.int(math.floor(9*new_theta))
[y, x] = np.meshgrid(np.arange(-SizeHalf,SizeHalf+1), np.arange(-SizeHalf,SizeHalf+1))
part1=(x-GCenter[0])**2+(y-GCenter[1])**2
GKernel = Gamp*np.exp(-0.5*Ggamma**-2*Gconst*part1)
return GKernel
def conv2(x,y,mode='same'):
"""
Emulate the Matlab function conv2 from Mathworks.
Usage:
z = conv2(x,y,mode='same')
"""
if not(mode == 'same'):
raise Exception("Mode not supported")
# Add singleton dimensions
if (len(x.shape) < len(y.shape)):
dim = x.shape
for i in range(len(x.shape),len(y.shape)):
dim = (1,) + dim
x = x.reshape(dim)
elif (len(y.shape) < len(x.shape)):
dim = y.shape
for i in range(len(y.shape),len(x.shape)):
dim = (1,) + dim
y = y.reshape(dim)
origin = ()
# Apparently, the origin must be set in a special way to reproduce
# the results of scipy.signal.convolve and Matlab
for i in range(len(x.shape)):
if ( (x.shape[i] - y.shape[i]) % 2 == 0 and
x.shape[i] > 1 and
y.shape[i] > 1):
origin = origin + (-1,)
else:
origin = origin + (0,)
z = convolve(x,y, mode='constant', origin=origin)
return z
# Create white noise array
N=50 # Noise array dimension
A=10 # Noise amplitude
noise = np.random.rand(N,N)*A
# Gaussian Noise paramerers
GCenter=[0,0]
Gconst=1
# First gaussian filter
cutoff_f1 = 0.05 # < pi/10
gamma1 = 1/(2*np.pi*cutoff_f1) #minimum gamma == 0.5
Gamp1 = 1/(2*np.pi*gamma1)
filtr1 = Gaussian2D([0,0],Gamp1,gamma1,Gconst)
# Second gaussian filter
cutoff_f2 = 0.04 # < pi/10
gamma2 = 1/(2*np.pi*cutoff_f2) #minimum gamma == 0.5
Gamp2 = 1/(2*np.pi*gamma2)
filtr2 = Gaussian2D([0,0],Gamp2,gamma2,Gconst)
# Convolve filters with noise
noise_filtr1 = conv2(noise, filtr1, mode='same')
noise_filtr2 = conv2(noise, filtr2, mode='same')
# Difference of Gaussian Output
noise_out = noise_filtr1- noise_filtr2