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.
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?