Time to be with your loved ones

Time to be with loved ones

by sat

submit your photo


Hall of Fame
View past winners from this year

Please participate in Meta
and help us grow.

Take the 2-minute tour ×
Photography Stack Exchange is a question and answer site for professional, enthusiast and amateur photographers. It's 100% free, no registration required.

I am wondering if there are any tools (standalone, Lightroom/Photoshop plugins, or other) that can take a photo, look for lines that are almost vertical or horizontal (eg horizons, telephone poles, etc), and automatically rotate and crop the image?

This is a manual process for me right now, and it seems like something that could be automated.

Does anything like this exist?

share|improve this question
2  
I was thinking Image Magick could pull this off, but then I found this: wizards-toolkit.org/discourse-server/… –  BBischof Dec 7 '10 at 6:35
2  
Be aware that rotating your image even a few degrees is a destructive operation comparable to running a blur filter over your image. That may be fine, but it's better to practice getting your images straight in the first place. (And/or use a camera which can automatically rotate its sensor slightly to match a level.) –  mattdm Dec 7 '10 at 14:49
    
if you use lanczos3 interpolation is it more like running a sharpening filter over it :) –  Michael Nielsen Feb 20 '13 at 7:56
    
Original, bilinear,bicubic,lanczos2: sequoiagrove.dk/images/rotateinterp.jpg –  Michael Nielsen Feb 20 '13 at 8:14
add comment

4 Answers

up vote 6 down vote accepted

There may well be programs that attempt to do what you descrive, but I'm doubtful it would be that effective. If the camera is pitched up or down slightly then you could have a perfectly level image, despite not having a single horizontal or vertical line.

The reason for this is that unless your camera is dead flat along the optical axis (that runs parrallel to the lens) then your telegraph poles etc. wont be veritcal in an image, even if the camera is level - the lines will all converge on an imaginary vanishing point in the sky. Likewise if the camera is not face on to a true horizontal line it wont be rendered horizontal in the image.

It's possible to employ a more sophisticated approach, by either trying to identify the horizon in images, or even better grouping lines that share a common vanishing point, estimating the pitch angle and thus the correct angle to rotate the image, but such a process would be considerably more involved.

share|improve this answer
    
How could an image processing program even know what is "level" –  Pat Farrell Jul 16 '12 at 2:10
    
@PatFarrell things like horizon, buildings, posts or signs, etc. I'd say it would be much easier than facial recognition or smile detection. –  Kirk Broadhurst Jul 17 '12 at 5:32
    
Where I live, you can rarely see the horizon, too many trees. I would guess that 99% of my photos don't have a sign, post, etc. in them. –  Pat Farrell Jul 22 '12 at 4:24
add comment

I totally second what Matt Grum stated...trying to automatically "level" an image based on a purely logical algorithm would really only be effective in the ideal situation: Where you have a perfectly flat horizon in a properly centered image that minimizes lens and perspective distortions.

Consider the scenario where you, as the photographer, did take a level shot of something, such as a lake, that does not have a perfectly "horizontally flat" shore...the shore curves around and eventually meets you. A computer algorithm may try to level such an image by making the shore of the lake as flat as possible...but that is incorrect. The shore of the lake should be tilted and eventually curve toward you. The human eye can detect such a thing, as it involves numerous cues from the whole scene, not just primary lines. Small things, such as how "upright" trees look (which can be a very ephemeral thing that would be difficult for a computer algorithm to accommodate).

I think this is one of those good arguments for doing the best you can in-camera, before you take the shot, to make sure your shots are level. Beyond the technical difficulties of accurately leveling shots with an automatic algorithm, non-90 degree rotations are one of the most destructive edits you can make, as it requires re-sampling each pixel in the image. If you can take your shots in-camera such that they are properly leveled, you won't have to perform any rotations causing that degradation in image detail.

share|improve this answer
add comment

Yes, I haven't done it and some C or python programming is involved, but I'm going to try soon.

My situation is a camera mounted on a mast which is on a a buoy taking a picture which always contains the horizon. This should be a simpler application than yours.

First, look in to OpenCV. Specifically the Hough Line Transform.

For my case, I expect that the horizon will be so much more distinctive than any other line, I can tune it to only find one line. I can then rotate based upon the line's angle.

For your application, I think you would filter out any line's more than X degrees out of horizontal or vertical.

A little statistics, and you may be able to figure out how much to rotate.

As to degraded image quality, I'll be converting RAW files to ppm instead of jpeg, so there shouldn't be much beyond some cropping.

share|improve this answer
add comment

Faststone has a feature for batch rotating. It's free and easy to use (for me).

Here I advised to use this software for batch watermarking, but there is a Tab for rotating (second tab, instead of #4 in the instruction).

share|improve this answer
1  
Does it calculate the amount of rotation from the images directly or do you have to tell it? –  Matt Grum Dec 7 '10 at 11:33
    
AFAIK, it gets actual rotation parameter from an image (that does a camera) –  Genius Dec 7 '10 at 13:43
3  
reread the question. Poster isn't just looking for 90° rotation based on the orientation sensor. –  mattdm Dec 7 '10 at 14:47
    
@mattdm, all answers above are theoretic only - no practical advises. So better to let the author to manually rotate all the pictures? ok. I've never seen any software that can do it automatically based on context, but in batch rotating mode you can do this work much faster than by doing it separately for every image. So lets see this answer as an additional to all answers above. –  Genius Dec 8 '10 at 7:48
3  
But Faststone doesn't do what the question asks, either, so it's less helpful than theoretical advice. –  mattdm Dec 8 '10 at 13:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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