32

I would like to rotate photos automatically, even when EXIF metadata about the image orientation is not available.

Are there any good algorithms for detecting the orientation of a photo? The images are photographs from a digital camera. The algorithm doesn't have to work perfectly, but any reduction in the amount of human interaction required to properly rotate photos would be a benefit.

I have found these two papers on the topic:

Pointers to other research and especially implementations are appreciated.

Luke Francl
  • 31,028
  • 18
  • 69
  • 91
  • It doesn't seem to be an algorithm for auto vertical/horizontal orientation, but it is the closest algorithm I could found with some implementations out there: deskew. Check ImageMagick deskew, or: http://www.google.com/codesearch/p?ct=rc#f0yt7jaEG7A/raster/deskewer.cpp – e.tadeu Jul 17 '09 at 18:21
  • 3
    You may also be interested in that people are considering the trick of rotating images as a new style of CAPTCHA. A small circular image is presented with an obvious (to us) object, but no clear horizon. I realize this doesn't help you, but it does underscore the depth of the problem. http://www.richgossweiler.com/projects/rotcaptcha/rotcaptcha.pdf – Omniwombat Jul 17 '09 at 19:47
  • @Luke Francl, i want to do a similar thing, so what did finally work out for you? – Lazer Oct 02 '09 at 07:01
  • @eSKay - nothing yet. I have left the question open in case there is something great out there. @smackfu has the best suggestion I think but there's nothing off-the-shelf to implement it. You'd have to write it yourself. I don't have a great need for this functionality right now so I haven't pressed further. – Luke Francl Oct 02 '09 at 17:58
  • Do you just want to detect which of the four edges of the image to choose as the top? Or do you want to be able to select any rotation throughout the 360 degrees? I can imagine there would be different approaches/algorithsm for the two cases. – hippietrail Aug 16 '17 at 23:58
  • I'm in the same position as you, only 8 years later ;- ) . Lots of stuff out there, I'm going to try `exiftrans` w Ubuntu. Did you see this paper? http://www.cs.toronto.edu/~guerzhoy/oriviz/crv17.pdf ? They clain 90%+ success on a multi-thousand picture set of end-user camera photos. (the example fail is very funny). Good luck! – shellter Feb 20 '19 at 20:13

3 Answers3

9

Many photographs from consumer digital cameras are of people, which could be used for orientation. Face detection is a well-studied research area. Basic face detection would give you a rectangle whose longer side should be the vertical dimension. Further, if you can detect the eyes/mouth, you should be able to pick the correct orientation of the rectangle.

Many other photographs are tourist snaps, where the sky is up and blue, and the ground is down and green.

Scott McIntyre
  • 1,365
  • 12
  • 24
  • 5
    Many face detection algorithms will not find faces that are upside down so you have to look for faces in all four possible directions. – Janusz Jul 17 '09 at 22:21
  • 2
    This is something that I've been considering since examining the papers I linked to above, because at least one of them uses face recognition as part of the algorithm. Since the vast majority of my photo corpus will include faces I think it may work well (assuming I can find a face recognition program that can recognize orientation, per Janusz). – Luke Francl Jul 17 '09 at 23:08
  • Many (most?) tourist snaps with sky in them have a white sky due to overexposure of the sky needed to properly expose the much darker main subject. – Michael C Dec 23 '19 at 23:39
  • Good idea, but lots of photos don't have people in them! – vy32 Dec 24 '19 at 15:24
4

I could only find http://sourceforge.net/projects/rotator/.

I used a test set of holiday photos comprising 70 pictures with about 18 requiring rotation.

After processing with the default settings, there were 20 that were either rotated or not rotated in error.

Not so great a result.

Earl
  • 181
  • 4
0

If the images are not square, you may be able to make the assumption that the default images are wider than they are tall. If that's the case determaning whether you need to rotate is just a matter of comparing the aspect ratio and rotating to reorient to default. Though you may end up with upside down images.

bdbaddog
  • 3,357
  • 2
  • 22
  • 33
  • 2
    This is only true for default images. Often people taking pictures of faces or people will turn the camera... – Janusz Jul 17 '09 at 22:22
  • True, but when people turn the camera to take such pictures, unless the faces are sideways or upside down, you may be able to use the aspect ratio for at least a hint. – bdbaddog Jul 20 '09 at 17:19
  • This is not true. Every object can be photographed in portrait or landscape orientation. And based on my images the ration is 60:40 (landscape to portrait). And if I have square image it will be because of postprocessing, not by camera. – Romeo Ninov Dec 23 '19 at 18:44
  • @Janusz, it depend a lot. You will find amazing portraits in landscape orientation – Romeo Ninov Dec 23 '19 at 18:45