如何指定二维差分高斯滤波器的带宽?

2024-10-02 12:37:09 发布

您现在位置:Python中文网/ 问答频道 /正文

这是一个关于高斯滤波器理论的问题,而不是具体的编码问题。

我有一个2D D.O.G的实现。python中的过滤器。我想在不同的空间频段制作噪声掩模,例如1-5 cpd。为此,我首先创建一个白噪声阵列,然后我将添加狗过滤器,以带通滤波器在不同的空间范围内过滤噪声。在

有没有一种方法可以明确定义不同的高斯滤波器的带宽与每个贡献高斯滤波器的参数?在

奖金Q:是否可以对这些高斯函数进行傅里叶变换,然后将其视为其各自带宽的频谱,然后再将其视为DOG带宽?傅立叶空间中的单位是什么?我怎么能把它转换成一个空间频率尺度?抱歉,有很多问题)

非常感谢

注意:我使用conv2函数来提高速度,而不是内置的python2d卷积(其他应用程序)。在

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

Tags: oflenmodenppiorigingaussiansame

热门问题