Easy way to Convert Magnitude/Phase back to Real/Imag 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 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?