Ask Your Question

How Do I Show value of the Angle After Completing Fourier Transform In Opencv?

asked 2014-06-05 07:40:07 -0500

rajib86 gravatar image

updated 2014-06-05 07:46:01 -0500

berak gravatar image

I am new in opencv. After completing Fourier transform, i have also got display the angle.I want to show in my window how many degree it is.please give me some idea.

// crop the spectrum, if it has an odd number of rows or columns
    canny_image = canny_image(Rect(0, 0, canny_image.cols & -2, canny_image.rows & -2));

 // rearrange the quadrants of Fourier image  so that the origin is at the image center
    int cx = canny_image.cols/2;
    int cy = canny_image.rows/2;

    Mat q0(canny_image, Rect(0, 0, cx, cy));   // Top-Left - Create a ROI per quadrant
    Mat q1(canny_image, Rect(cx, 0, cx, cy));  // Top-Right
    Mat q2(canny_image, Rect(0, cy, cx, cy));  // Bottom-Left
    Mat q3(canny_image, Rect(cx, cy, cx, cy)); // Bottom-Right

    Mat tmp;                           // swap quadrants (Top-Left with Bottom-Right)

    q1.copyTo(tmp);                    // swap quadrant (Top-Right with Bottom-Left)

    normalize(canny_image, canny_image, 0, 1, CV_MINMAX); // Transform the matrix with float values into a
                                            // viewable image form (float between values 0 and 1).
 imshow("spectrum magnitude", canny_image);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-06-05 09:03:33 -0500

kbarni gravatar image

updated 2014-06-05 09:05:23 -0500

First split the complex (2 channel) image in two separate images containing the real and imaginary part:

Mat planes[2];

...assuming that the canny_image is complex. Then use the cartToPolar function to get the phase (angle) and magnitude:

Mat magn,angl;

The last parameter (true) defines that you want the results in degrees.

You can do this in two steps using the magnitude and phase functions in a similar manner.

More info here:

edit flag offensive delete link more


Thanks for your replay.I have flow your instruction.But i need to calculate the angle,How many degree, example 45 degree, in my screen it will show 45 degree. Mat magnitude,angl; cartToPolar(planes[0],planes[1], magnitude,angl,true); cout << "degree=" <<true << endl; log(magnitude,magnitude); magnitude = magnitude(Rect(0, 0, magnitude.cols & -2, magnitude.rows & -2));

rajib86 gravatar imagerajib86 ( 2014-06-08 10:06:28 -0500 )edit

Oh, I see. You don't want to get the angle (phase) of the Fourier transform, you want to get the dominant orientation of the image!

In this case, you have to check which is the direction with the most intensity from the center of the image. The easiest way to do this is to transform the magnitude matrix with a LogPolar transform, then make a horizontal sum of the elements (reduce function), finally search for the position of the maximum (minmaxloc function).

kbarni gravatar imagekbarni ( 2014-06-10 03:10:25 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2014-06-05 07:40:07 -0500

Seen: 1,986 times

Last updated: Jun 05 '14