简体   繁体   中英

Extending 1D function across 3 dimensions for data windowing

For the sake of image (volume) registration, I'd like to apply a windowing function to input data, such that the non-periodic image boundaries do not cause streaking in the FFT. I'm using the example from here for 2D data:

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

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

Is this extensible to 3D or even ND?

@nivag at Signal Processing pointed out that each dimension can be treated independently: https://dsp.stackexchange.com/questions/19519/extending-1d-window-functions-to-3d-or-higher

Here is the code I came up with (with revision help from the scikit-image team):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM