在频域中相乘图像
我一直在频域中处理图像(通过对图像进行 DFT 或 FFT),并且我知道空间域中的卷积是频率的乘法。
所以我的问题是,如果我想在空间域中应用特定的内核(比如说 9x9 平滑内核),我只需通过 9x9 滤波器对整个图像进行卷积即可。现在,如果我想在频域中做同样的事情,我是否需要对图像和内核进行 FFT?那么我该如何/乘什么?在获得新的数据集(图像乘以内核)后,我只需反转 FFT 的方向,这应该会得到与内核与空间域中的图像卷积相同的结果,对吗?
感谢您的帮助!
I've been working with images in the frequency domain (by taking the DFT or FFT of an image) and I know that convolution in the space domain is multiplication in the frequency.
So my question is, if I wanted to apply a specific kernel (lets say a 9x9 smoothing kernel) in the space domain, I would just convolve the whole image by the 9x9 filter. Now, if I wanted to do the same thing in the frequency domain, do I take the FFT of both the image and the kernel? Then how/what do I multiply? After I have that new set of data (image multiplied by kernel), I just reverse the direction of the FFT and that should give me the same result as the kernel convolved with the image in the space domain, right?
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IIRC,设法让您的 FFT 图像和内核(均为 FFT'd)具有相同的尺寸,然后将两个 FFT 图像逐像素相乘,然后对结果进行反 FFT。
注意图像边界发生的情况(请参阅 FFT 理论)。
IIRC, manage to have your FFT'd image and kernel (both FFT'd) of the same dimensions, then multiply pixel-by-pixel both FFT'd images, then inverse FFT the result.
Take care of what happens to the borders of your image (see FFT theory).
请注意,FFT 乘法与循环卷积相同(例如,就好像数据的边缘环绕一样)。如果您不希望卷积结果产生这些圆形边缘效应,则可以对数据进行零填充,至少将卷积核的非零长度加上 1。您还必须对卷积核进行零填充,以使其具有相同的长度。
例如,在您的情况下,您可以使用长度 522 FFT (512 + 9 + 1),或者可能使用具有较小价格因素的 540 长度 FFT(FFTW 库可用于非常高效的非 2 次幂 FFT) ),或者如果必须使用 2 的幂,则将零填充一直到长度 1024 FFT。
正如 @maola 的答案,数据和内核的 FFT 必须具有相同的长度(否则您的频率相乘不匹配),并且您必须在频域中进行复杂的乘法。
Note that FFT multiplication is the same as circular convolution (e.g. as if the edges of your data wrapped around). If you don't want these circular edge effects from the convolution results, you can zero pad your data by at least the nonzero length of your convolution kernel plus 1. You also have to zero pad your convolution kernel to give it the same length.
For instance, in your case you could use a length 522 FFT (512 + 9 + 1), or maybe a 540 length FFT which has smaller price factors (the FFTW library can be used for very efficient non-power-of-2 FFTs), or zero pad all the way up to a length 1024 FFT if you have to use a power of 2.
As in @maola's answer, both FFTs of the data and the kernel must be of the same length (or else the frequencies you are multiplying won't match), and you have to do complex multiplication in the frequency domain.