简体   繁体   English

OpenCV并使用傅立叶变换dft()

[英]OpenCV and working with Fourier transform dft()

I am trying to point-wise multiply fourier transforms of two separate images and then convert back to a normal image. 我试图逐点乘以两个单独图像的傅里叶变换,然后转换回正常图像。 I'm not very familiar with using the fourier transform in OpenCV but this is what I have at the moment. 我不太熟悉在OpenCV中使用傅立叶变换,但这就是我现在所拥有的。 The last line where the output is shown causes an exception of type 'System.Runtime.InteropServices.SEHException' but I can't figure out how to fix it. 显示输出的最后一行导致类型'System.Runtime.InteropServices.SEHException'的异常,但我无法弄清楚如何修复它。 I have tried various different parameters and functions at each stage but all seem either give an exception or an empty output. 我在每个阶段尝试了各种不同的参数和函数,但似乎都给出了异常或空输出。 What am I doing wrong? 我究竟做错了什么? Thanks for any help you can give me! 感谢你给与我的帮助!

Mat dftInput1, dftImage1, dftInput2, dftImage2, multipliedDFT, inverseDFT, inverseDFTconverted;

image1.convertTo(dftInput1, CV_32F);
dft(dftInput1, dftImage1, DFT_COMPLEX_OUTPUT);
image2.convertTo(dftInput2, CV_32F);
dft(dftInput2, dftImage2, DFT_COMPLEX_OUTPUT);

multiply(dftImage1, dftImage2, multipliedDFT);

idft(multipliedDFT, inverseDFT, DFT_SCALE);
inverseDFT.convertTo(inverseDFTconverted, CV_8U);
imshow("Output", inverseDFTconverted);

imshow can't show 2 channel images, only 1,3,4 channel ones. imshow无法显示2个频道的图像,只有1,3,4个频道的图像。

if you use DFT_COMPLEX_OUTPUT for the dft, you get a 2 channel image, applying the reverse idft again produces a 2channel(complex) Mat 如果您使用DFT_COMPLEX_OUTPUT作为dft,您将获得一个2通道图像,应用反向idft再次生成一个2通道(复杂)Mat

no idea, why you get a 'System.Runtime.InteropServices.SEHException' though ( is that 'managed c++' ? ) 不知道,为什么你得到'System.Runtime.InteropServices.SEHException'(是'托管c ++'?)

convertTo() changes the type of the channels, but not their count (yea, surprise). convertTo()改变了频道的类型,但不改变它们的数量(是的,惊喜)。

so, either restrict it to the real part: 所以,要么限制它到真实的部分:

 idft(multipliedDFT, inverseDFT, CV_DFT_SCALE | CV_DFT_REAL_OUTPUT );

or split it , and throw only the real part at imshow: 或拆分它,并只在imshow抛出真实的部分:

Mat chan[2];
split( inverseDFTconverted, chan );
imshow("lalala", chan[0]);

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

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