functions magnitude and phase (Bug #1619)


Added by Junbin Gao about 13 years ago. Updated almost 13 years ago.


Status:Cancelled Start date:2012-02-23
Priority:High Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:core
Target version:2.4.0
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

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.

 1int main(int argc, char ** argv)
 2{
 3    Mat A =  (Mat_<float>(4, 4) << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
 4    Mat B;
 5    Mat planes2[] = {A, Mat::zeros(A.size(), CV_32F)};
 6    merge(planes2, 2, B);
 7    dft(B,B);
 8    split(B, planes2); 
 9    cout << "Real=" << planes2[0]  << endl;
10    cout << "Imag=" << planes2[1]  << endl;
11
12    /*magnitude(planes2[0], planes2[1], A);
13    cout << planes2[0] << endl;
14    cout << planes2[1] << endl;
15    cout << "Mag = " << A << endl;*/
16
17    phase(planes2[0], planes2[1], A);
18    cout << "Angles = " << (180.0 / 3.141592653589793)*A << endl;
19
20    A =  (Mat_<float>(4, 4) << 136, -8, -8, -8, -32,0,0,0, -32,0,0,0, -32,0,0,0);
21    B =  (Mat_<float>(4, 4) << 0, 8, 0, -8, 32, 0, 0, 0, 0, 0, 0, 0, -32, 0, 0, 0); 
22    phase(A,B,A);
23    cout <<"Four Angles = " << (180.0 / 3.141592653589793)*A << endl;
24
25    getchar();
26    return 0;
27}

History

Updated by Vadim Pisarevsky about 13 years ago

check your code; planes2[0] is the same matrix as A, so phase() indeed changes it.
use Mat planes2[] = {A.clone(), Mat::zeros(A.size(), CV_32F)}; to avoid this problem

  • Status changed from Open to Cancelled

Updated by Andrey Kamaev almost 13 years ago

  • Target version set to 2.4.0
  • Description changed from I was trying to reconstructed an image from only phase information of its FFT... to I was trying to reconstructed an image from only phase information of its FFT... More
  • Category set to core
  • Assignee set to Vadim Pisarevsky

Also available in: Atom PDF