Updated by Andrey Kamaev almost 13 years ago

I was trying to reconstructed an image from only phase information of its FFT which can give an estimate of edges in image, that can be done in matlab (phase given by the angle function). However when I work on OpenCV, first I worked out phase by OpenCV phase function, and then apply idft to the result. The result is not I want. After exploring phase function, I found the values given by phase is between 0 and 2pi, not -pi and pi as matlab. I adjust the results from phase to -pi and pi, but what surprises me is that both function magnitude(x,y,m) and phase(x,y,a) make changes to y which is not supposed to do. I am not sure whether this a bug.

Please test the following program, without calling magnitude before phase, we see the same results from two phases, but uncomment the statement magnitude, the results are different.

<pre><code class="cpp">
int main(int argc, char ** argv)
{
Mat A = (Mat_<float>(4, 4) << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
Mat B;
Mat planes2[] = {A, Mat::zeros(A.size(), CV_32F)};
merge(planes2, 2, B);
dft(B,B);
split(B, planes2);
cout << "Real=" << planes2[0] << endl;
cout << "Imag=" << planes2[1] << endl;

/*magnitude(planes2[0], planes2[1], A);
cout << planes2[0] << endl;
cout << planes2[1] << endl;
cout << "Mag = " << A << endl;*/

phase(planes2[0], planes2[1], A);
cout << "Angles = " << (180.0 / 3.141592653589793)*A << endl;

A = (Mat_<float>(4, 4) << 136, -8, -8, -8, -32,0,0,0, -32,0,0,0, -32,0,0,0);
B = (Mat_<float>(4, 4) << 0, 8, 0, -8, 32, 0, 0, 0, 0, 0, 0, 0, -32, 0, 0, 0);
phase(A,B,A);
cout <<"Four Angles = " << (180.0 / 3.141592653589793)*A << endl;

getchar();
return 0;
}
</code></pre>

Back