# Finding an Image's Orientation With DFT Frequency Amplitudes

I'm looking to get some general idea of an image's orientation so that I can then rotate it to the nearest 90 degree angle.

My idea on how to do this is to take the DFT on the image, then do a "radar sweep" to find which angle has the greatest sum of frequency amplitudes along the line, and call the winning angle the orientation.

I scan from 0 to 180 degrees instead of from 0 to 360, and make the radar sweep double sided since negative and positive frequencies seem to belong together.

For example, if i take the DFT of this image: The frequency amplitudes are: And if I do a radar sweep, I'd find the winning line / angle here: Using that information, I can know where the nearest 90 degrees is for that blue line, figure out how much i'd need to rotate the dft image to make that blue line vertical, but instead rotate the source image by that amount, to make that image orient towards the nearest 90 degrees.

Something like this, but actually level (I'm working out some bugs at the moment, in my implementation) Is this method sound? Are there any complications that I'm going to encounter when moving to more complex images such as complex patterns or photographs?

Edit: In the above I didn't explain the reasoning for what I am doing.

If you take the dft of simple images - like a single line, or a repeating pattern of black and white stripes - the resulting frequency amplitudes image has data that runs perpendicular to the direction of that line or those stripes.

Line this: DFT'ing to this: May (possibly naive!) understanding is that I should then be able to tell which direction (from the center) has the highest sum, and that will tell me the angle perpendicular to the largest represented orientation of the image.

From there, i can find how much i'd have to rotate that line to get to the nearest 90 degrees, and apply that rotation to the source image, to make it line up to it's nearest 90 degrees.

Is my thinking too simplistic, or is this a solid approach?

• I'd like to give the bounty to someone, but the answers I got, as good as they are (!) don't answer my question, just give alternatives to doing it the way I'm doing it. – Alan Wolfe Aug 10 '16 at 21:46

Have you heard of the Hough Transform? It is a possible alternative for tackling your problem.

• Let me know, in case you have specific questions. There is a lot of literature available. Implementation of the algorithm is rather easy and can be done in computational efficient ways, by e.g. vectorization/parallelization. – Peter Pablo Aug 3 '16 at 21:44