Jump to content
  • entries
    341
  • comments
    905
  • views
    262,493

Horizon detection for creating panoramas


One big challenge creating panoramas (see my gallery at http://sites.google.com/site/ericballpanorama) is getting the horizon right. This is particularly true for panoramas looking out at the ocean which spans multiple photos. This is because you have to get 2 things absolutely correct:

  1. The horizon must be straight level. Even if the photos were taken with a tripod, it doesn't take much for the horizon to be at a slight angle. Additionally, if the photo was taken looking slightly up or down or from any height then the horizon will be a curve in the photo.
  2. The horizon must line up between photos. If the horizon doesn't match up perfectly between photos there will be a step at the transition.

In theory the way to correct this in Hugin is by setting multiple straight line and horizontal line control points on the horizon. Then the optimization process should correct the pitch and roll along with any curvature caused by lens distortion. The problem is then placing those control points. Unfortunately, the horizon (especially from a JPEG photo) is not a simple line or edge. While it might look sharp at normal size, zoomed in the transition is blurry and not distinct. And from what I've been able to determine, there's no existing solution.

 

So I've done some research and programming.

 

The first step is "edge detection". I'm using a technique based on "Phase Congruency" described by Peter Kovesi http://www.csse.uwa.edu.au/~pk/Research/research.html The logic is an edge can be described as the point where the maximum number of frequency components are in phase with one another. To calculate this I do a 32 sample FFT, discard the DC and Nyquist samples, then calculate the resulting inverse FFT of it and it's Hilbert transform then combine them. Because I'm looking for the horizon, which should be roughly horizontal, I only need to do this in one direction across the entire photo. The resulting output nicely highlights the horizon, but is still several pixels wide. (I also limit the calculation to a band containing the horizon, both to reduce noise and calculation time.)

 

So the next step is I do a kind of Hough Transform across the band. For each x coordinate, I take a block of pixels as many pixels wide as the band is high and draw all possible lines from the left to the right edge. The brightest line is deemed the correct line for the horizon and I store the Y coordinate of the middle of the line. The resulting series of X & Y coordinates should be the horizon and can be used as control points.

0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...