gpt4 book ai didi

python - 将 1D 函数扩展到 3 个维度以进行数据窗口

转载 作者:行者123 更新时间:2023-12-01 04:56:10 25 4
gpt4 key购买 nike

为了图像(体积)配准,我想对输入数据应用窗口函数,以便非周期性图像边界不会导致 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 维吗?

最佳答案

信号处理的@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

关于python - 将 1D 函数扩展到 3 个维度以进行数据窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27345861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com