Ask Your Question
1

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

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

rajib86 gravatar image

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

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)
    q0.copyTo(tmp);
    q3.copyTo(q0);
    tmp.copyTo(q3);

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

    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
2

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

kbarni gravatar image

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

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

Mat planes[2];
split(canny_image,planes);

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

Mat magn,angl;
cartToPolar(planes[0],planes[1],magn,angl,true);

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: http://docs.opencv.org/modules/core/doc/operations_on_arrays.html

edit flag offensive delete link more

Comments

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 -0600 )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 -0600 )edit

Question Tools

Stats

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

Seen: 2,568 times

Last updated: Jun 05 '14