2
$\begingroup$

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:

enter image description here

The frequency amplitudes are:

enter image description here

And if I do a radar sweep, I'd find the winning line / angle here:

enter image description 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)

enter image description here

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:

enter image description here

DFT'ing to this:

enter image description here

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?

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – Alan Wolfe
    Aug 10, 2016 at 21:46

2 Answers 2

2
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$ Aug 3, 2016 at 21:44
2
+50
$\begingroup$

Histogram of the gradient directions:

You can also try by computing the gradient directions on every pixel, for instance using the Canny edge detector. You will wrap the angle to the range [0°, 180°).

Then compute the histogram of the angles, say with a 1° resolution. The dominant direction should appear as the most populated bin.

Instead of merely counting the pixels, you can weight the sum with the gradient magnitude, to favor strong edges and reduce the effect of noise.

$\endgroup$
5
  • $\begingroup$ Thanks for the alternative, I appreciate hearing about that! Do you know whether the method i describe is sound or not? $\endgroup$
    – Alan Wolfe
    Aug 5, 2016 at 16:11
  • $\begingroup$ @AlanWolfe: how do you justify it ? $\endgroup$
    – user7657
    Aug 5, 2016 at 16:13
  • $\begingroup$ Edited the question to add that, thank you for asking! Hopefully you'll be able to see what I'm going for... $\endgroup$
    – Alan Wolfe
    Aug 5, 2016 at 16:23
  • $\begingroup$ A stripe image is essentially 1D and has a single-line DFT. This doesn't generalize to real images. $\endgroup$
    – user7657
    Aug 5, 2016 at 16:31
  • $\begingroup$ Wouldn't there be a "prominant stripe" through the middle perpendicular to where the most orienting angle is? I see evidence of that in images I've DFT'd at least. $\endgroup$
    – Alan Wolfe
    Aug 5, 2016 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.