简体   繁体   English

numpy 中的二维傅里叶变换的频率基础是如何选择的?

[英]How is the frequency basis chosen for 2d fourier transform in numpy?

I'm converting 2D (spatial) images to that of the frequency domain using tf.signal.fft2d (in numpy: np.fft.fft2 ) and notice that the start and end shapes are the same, although I don't see why they have to be.我正在使用tf.signal.fft2d (在 numpy: np.fft.fft2中)将 2D(空间)图像转换为频域图像,并注意到开始和结束形状是相同的,尽管我不明白为什么他们必须是。 For example:例如:

test_img = np.random.rand(100, 100) # shape (100, 100)
spectral = np.fft.fft2(test_img)

# -> spectral.shape = (100, 100)

Given that the image is now in the spectral basis - how are the basis elements chosen in NumPy (and Tensorflow as the implementations are the same)?鉴于图像现在处于光谱基础 - NumPy(和 Tensorflow 因为实现相同)中如何选择基础元素? Specifically, what are the starting (lowest) frequencies, and how are the more periodic ones chosen?具体来说,什么是起始(最低)频率,以及如何选择更具周期性的频率?

Why do you expect the two axis to be of different length?为什么您期望两个轴的长度不同?

By default, the FFT is computed on the points you supply, resulting in a 2D array that (correctly) has the same shape of the input.默认情况下,FFT 是在您提供的点上计算的,从而产生一个(正确地)具有与输入相同形状的二维数组。 To change this behavior, you must provide the s parameter to fft2 (see the docs ).要更改此行为,您必须向fft2提供s参数(请参阅文档)。 For example, in your case, calling np.fft.fft2(test_img, s=(200, 100)) will result in an output of shape (200, 100) .例如,在您的情况下,调用np.fft.fft2(test_img, s=(200, 100))将导致形状为(200, 100)的 output 。 This is internally obtained by zero padding your input (ie adding 100 trailing zeros along the the first dimension), and computing the FFT on the resulting matrix.这是通过对输入进行零填充(即沿第一个维度添加 100 个尾随零)并在结果矩阵上计算 FFT 来在内部获得的。

As a general rule, for a FFT output of shape (N, M) , the (normalized) frequency basis will be 1/N on axis 0 and 1/M on axis 1. To convert them to an actual frequency you need to multiply each by the sampling frequency of the respective dimension.作为一般规则,对于形状为(N, M)的 FFT output ,(归一化)频率基础将是轴 0 上的1/N和轴 1 上的1/M 。要将它们转换为实际频率,您需要乘以每个由各自维度的采样频率。

Be aware that when you compute double-sided FFT (as you are doing), you'll have positive frequencies up to Nyquist in the first half, and negative frequencies in the second half (see this page )请注意,当您计算双面 FFT 时(正如您所做的那样),您将在前半部分获得高达奈奎斯特的正频率,在后半部分获得负频率(参见此页

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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