OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sat, 13 Jun 2015 12:39:00 -0500Easy way to Convert Magnitude/Phase back to Real/Imag for DFT?http://answers.opencv.org/question/64091/easy-way-to-convert-magnitudephase-back-to-realimag-for-dft/I'm facing a poblem in OpenCV4Android. I'm trying to do a phase recovery of an incoming image like the [Gerchber-Saxton algorithm](http://en.wikipedia.org/wiki/Gerchberg%E2%80%93Saxton_algorithm) does.
I'm propagating the lightfield with a "Fresnel-Propagator" along Z-axis. This works quiet well. In Matlab code I have a complex-datatype with phase/magnitude as well as real/imaginary part. I'm having no problems to switch forth and back, but in OpenCV the exact same operation seems to have no proper result. Converting back and forth doesnt give same results
I've written some code for Imag/Real conversion like the one below (real sin is simply a cosine)
Mat toImag(Mat magMat, Mat phaseMat) {
Mat resultMat = new Mat(magMat.size(), magMat.type());
for (int iwidth = 0; iwidth < magMat.width(); iwidth++) {
int mag=0, phase=0;
double imag=0;
for (int iheight = 0; iheight < magMat.height(); iheight++) {
mag = (int)magMat.get(iwidth, iheight)[0];
phase = (int)phaseMat.get(iwidth, iheight)[0];
imag= mag*sin(phase);
resultMat.put(iwidth, iheight, imag);
}
}
The alternative was using PolarToCart-function, but I'm not sure if I could use it to convert the Euler-representation of a compolex number to compnent-representation. Does anybody know how to solve this issue?
beniroquaiSat, 13 Jun 2015 12:39:00 -0500http://answers.opencv.org/question/64091/