I'm trying to convert this simple Matlab code to C++ with openCV:
localstd=sqrt(abs(ifft2(fft2(output).*gf)));
It means taking the fft of the matrix "output", multiplying it element by element with the matrix "gf", then taking the ifft of that and then taking the magnitude of that.
I'm trying the following simple code:
Mat complexI;
dft(output, complexI,cv::DFT_SCALE||DFT_COMPLEX_OUTPUT);
Mat copmlexI2=Mat(n,n,CV_32F);
mulSpectrums(complexI,gf,copmlexI2,DFT_COMPLEX_OUTPUT);
dft(copmlexI2,copmlexI2,cv::DFT_INVERSE||DFT_COMPLEX_OUTPUT);
Mat planes[]= {Mat::zeros(output.size(), CV_32F), Mat::zeros(output.size(), CV_32F)};;
split(copmlexI2, planes); // planes[0] = Re(DFT(I), planes[1] = Im(DFT(I))
magnitude(planes[0], planes[1], planes[0]);// planes[0] = magnitude
Mat localstd = planes[0];
for (int i=0;i<localstd.rows;i++){
for (int j=0;j<localstd.cols;j++){
localstd.at<float>(i,j)= sqrt(localstd.at<float>(i,j));
}
}
for (int i=0;i<localstd.rows;i++){
for (int j=0;j<localstd.cols;j++){
localstd.at<float>(i,j)/= 255;
}
}
It's very simple. I'm taking the dft of "output", multiply it's spectrum with "df" and take the ifft of that. Next, I split the result into the real and imaginary plane and take the magnitude. Finally, I take the sqrt of that and normalize by dividing with 255.
The results I get are very different than what I get in Matlab. What am I missing here? Any ideas on how to fix the code?
Thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…