使用 MathNet 进行傅里叶变换卷积时,生成的图像的象限交换了

问题描述 投票:0回答:1

我正在做一些相对简单的事情,就像这样:

// image and kernel are both 512 x 512
Matrix<Complex> image = GetImage();
Matrix<Complex> kernel = GetKernel();

// Apply FFT to both image and kernel
Fourier.Forward2D(image, FourierOptions.NoScaling);
Fourier.Forward2D(kernel, FourierOptions.NoScaling);

// Multiply matrices to do convolution in frequency domain
Matrix<Complex> convolved = image.PointwiseMultiply(kernel);

// Apply inverse FFT to get image in spatial domain
Fourier.Inverse2D(convolved, FourierOptions.NoScaling);

但是,生成的图像的象限被交换了。如果你要把原始图像分成这样的象限:

 -------
| 1 | 2 |
|-------|
| 3 | 4 |
 -------

最终图像有这样的象限:

 -------
| 4 | 3 |
|-------|
| 2 | 1 |
 -------

内核只是一个全为零的图像,除了中心像素(256, 256)的值为 1.0。

c# image-processing fft mathnet-numerics mathnet-filtering
1个回答
0
投票

您的问题是在计算 FFT 的方式中遇到符号约定。通过将单个像素设置为 (256,256),您实际上表示要将整个图像移动 +256,+256。

如果您希望图像保持原样,那么您应该将 PSF 集中在像素 (0,0) 上,而其他部分则潜伏在图像的角落中。另一种方法是在进行变换后移动生成的卷积图像。

您必须记住,FFT 中存在隐含的周期性边界条件。因此,您可能需要图像周围有一个零保护带,该保护带仅比卷积 PSF 宽度的一半宽一点。否则边缘不连续性会从上到下、从左到右泄漏,反之亦然。

© www.soinside.com 2019 - 2024. All rights reserved.