Reputation: 390
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. 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. 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);
Upvotes: 1
Views: 4171
Reputation: 39796
imshow can't show 2 channel images, only 1,3,4 channel ones.
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
no idea, why you get a 'System.Runtime.InteropServices.SEHException' though ( is that 'managed c++' ? )
convertTo() changes the type of the channels, but not their count (yea, surprise).
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:
Mat chan[2];
split( inverseDFTconverted, chan );
imshow("lalala", chan[0]);
Upvotes: 2