在3维上扩展1D功能以进行数据窗口化

时间:2014-12-07 17:57:50

标签: python numpy scipy signal-processing linear-algebra

为了图像(体积)配准,我想应用窗口函数来输入数据,这样非周期性图像边界不会在FFT中产生条纹​​。我正在使用这里的示例来获取2D数据:

http://mail.scipy.org/pipermail/numpy-discussion/2008-July/036112.html

h = scipy.signal.hamming(n)
ham2d = sqrt(outer(h,h))

这可以扩展到3D甚至是N-D吗?

1 个答案:

答案 0 :(得分:2)

Signal Processing的@nivag指出,每个维度都可以独立处理: https://dsp.stackexchange.com/questions/19519/extending-1d-window-functions-to-3d-or-higher

以下是我提出的代码(来自scikit-image团队的修订帮助):

def _nd_window(data, filter_function):
    """
    Performs an in-place windowing on N-dimensional spatial-domain data.
    This is done to mitigate boundary effects in the FFT.

    Parameters
    ----------
    data : ndarray
           Input data to be windowed, modified in place.
    filter_function : 1D window generation function
           Function should accept one argument: the window length.
           Example: scipy.signal.hamming
    """
    for axis, axis_size in enumerate(data.shape):
        # set up shape for numpy broadcasting
        filter_shape = [1, ] * data.ndim
        filter_shape[axis] = axis_size
        window = filter_function(axis_size).reshape(filter_shape)
        # scale the window intensities to maintain image intensity
        np.power(window, (1.0/data.ndim), output=window)
        data *= window