August 30, 2005

Software tools for creating panoramic images

Author: Nathan Willis

You just got back from vacation, and the scenic vistas of Black Canyon of the Gunnison and sunset on the Ganges that seemed so awe-inspiring in person look flat and forgettable now that you're home looking at them on your monitor or, worse yet, on 4x6-inch prints. Open source software has some tools that can make your images come alive.

The reason for the flat look of most photos is pretty simple: Human eyes have about a 140° field of view. Your camera lens, on the other hand, probably maxes out between 40° and 65° at best. So your pictures don't even come close to capturing the true experience.

To get better pictures next year, you can start saving your pennies now to buy a specialty panoramic-view camera, or you can put that money towards your airfare and use free software to magically knit together your small pictures into grand, applause-worthy panoramic landscapes.

Of course, there are more serious applications of panoramic image processing; taking detailed pictures of any large object can require stitching together multiple images. NASA, astronomers, aerial photographers, and the CIA satellite over your house need to do it every day: Take separate images, tile them, align them, and stitch them together. And when scientific discovery is at stake, you know that they will make sure the math is correct.

So let's get started. Step one is the easiest: Travel to an exotic location and take a bunch of pictures. Make sure they overlap at least a little so you won't have any gaps. Tutorials can give you a lot of advice on how to set up your camera, tripod, handyman level, and exposure to get clean images ready to be sewn together. When you get back, download or scan in your photos, then prepare to download some software.

A stitch in time

The current reigning champ of open source panorama creation is Hugin, which NewsForge profiled last week. You can use Hugin to stitch together your photos into a seamless whole, and to do far more.

Hugin is a descendant of PanoTools, an excellent suite of panorama processing applications first developed by German university professor Helmut Dersch. The original PanoTools are no longer being developed, but derivatives like Hugin and other (less advanced) projects are; see the PanoTools wiki for details.

This family of applications is not your only choice. If you find some of Hugin's options intimidating, you can start simpler with Enblend. Enblend is a command-line tool that composites multiple images and blends away the seams, though for outdoor shots, it is hard to avoid the "vignette" look caused by light falloff at the edges of the frame, especially in blue sky, where scattered light dominates.

Mono users can try autopano-SIFT, an implementation of Scale-Invariant Feature Transform (SIFT). SIFT's specialty is automatically finding the "interesting" features of an image. When stitching together image sets, these interesting features become the control points -- those features present in two or more adjacent image tiles that the software must line up in order to make a seamless stitch.

If you prefer to choose the control points yourself, try PanoPoints, a perl-GTK program that relies on you to identify the interesting features. PanoPoints may do a better job than a program that uses automated techniques if your first choice seems to be choosing incorrectly for your image.

Wearable-computing guru Steve Mann's researchers have produced the stitcher VideoOrbits. This toolkit grew out of the desire to make composite images for augmented reality displays. In addition to stitching together panoramic tiles, it can be used to composite multiple exposures for increased tonal range (e.g. combining a picture showing shadow detail with one showing highlight detail so you can see both).

Escaping the reality distortion field

A good panoramic picture beats a single photo taken by a super-wide-angle lens, for a couple of reasons. First, you have perspective distortion: The lens is directional, so objects in the center of the frame will be greatly enlarged compared to those in the periphery. Second, in our imperfect world, all lenses have some barrel distortion, which results in the visible curving of what should be straight lines.

To correct barrel distortion, you can use almost any PanoTools-derived package, or choose between two independent projects, the GUI tool PTLens and the command-line clens. PTLens was developed by Thomas Niemann, and clens by a SourceForge group that wanted to preserve the last release of PanoTools.

Both rely on a database of precise camera and lens information to calculate the necessary transforms. Image files that contain EXIF tags include the camera and lens information, and these applications can read that in automatically. If your particular camera/lens combination is not in the database, you can send a sample shot to Thomas Niemann, and he will calculate the distortion and add the findings to the next release of the database.

I've been around free software for years, and I've got to say, that's pretty friendly. There are several closed-source, commercial applications for distortion correction, and I guarantee they won't offer to do the work for you.

Plus -- as was the case with image stitching -- there are many other uses for distortion correction. The millionaires among us can buy tilt-shift lenses and cranes to get into any shooting position their hearts desire, but for the rest of us the ability to computationally correct for angle, perspective, and aberration is indispensable.

Degrees of freedom

Of course, your skills at creating panoramic images won't matter if you
can't view panoramic images. The simplest output technique for a panorama
is a long, skinny image file (JPEG or TIFF) that you can share with anyone. These are referred to as rectilinear panoramas.
Flickr
has severalgroupsdevoted to the care and maintenance of panoramic images, and certain inkjet printers are capable of printing on long rolls of paper so you have something to hang on the wall.

Sooner or later, though, you will want to try your hand at making a 360° panorama, either a full-spherical panorama (360° around, 90° up and 90° down) or a partial-spherical, like a cylindrical projection. For these, you'll need a special viewer.

Friends shackled to non-free operating systems can use Apple's QuickTime plugin to view QuickTimeVR panoramas. The QuickTime plugin is installable under WINE.

Note, however, that QuickTimeVR supports only certain panorama formats. For unsupported formats, you must use the shareware PanoCube converter.

A better alternative is the open source Java applet PTViewer. It, too, is a descendant of PanoTools, but it has been picked up, maintained, and enhanced by Fulvio Senore.

In a development that's good from a technical standpoint but confusing from a user standpoint, PanoTools creator Helmut Dersch has recently picked up development of PTViewer again, creating a separate branch with other features, including mobile device support.

Lastly, the Hugin project hosts Panoglview, an OpenGL-accelerated viewer still in beta.

Send lawyers, lenses, and money

Perhaps you've wondered why so many of the aforementioned tools have common roots in PanoTools, a package seemingly abandoned by its creator. Here's the story. PanoTools was first released by Helmut Dersch in 1998, the result of endless hours of hard work rooted in solid mathematics done by someone with a good understanding of optics. Hugin and other derivatives have made the computational core more user-friendly, but few algorithms still needed improvement.

Trouble started in 2001 when Dersch became the target of legal harassment by a US company called IPIX. IPIX sent threatening letters to Dersch, other free software developers, and several commercial competitors, accusing them of infringing on the company's patents.

Many in the Virtual Reality and immersive imaging communities questioned the validity of these patents, citing years (in some cases, decades) of prior art, the vagueness of the claims made (the technique they patented was for an 8mm lens, but the claim was written so broadly as to suggest it covered any wide-angle lens), and timing of the claims to coincide with the company's imminent IPO.

Dersch cleared most of the material on his Web site, but removed the site, as he could not afford a court battle if IPIX did sue him. Nevertheless, he permitted anyone who possessed the software to redistribute it and continue development.

IPIX settled another case with a commercial competitor out of court and has remained relatively quiet in recent years -- perhaps in reaction to a number of anti-IPIX campaigns, which continued to amass evidence discrediting the disputed patents.

Today, most of the software that the company tried to bully into hiding at the zenith of the dot-com bubble is back online -- and if you're curious, you can check IPIX's financial status at Yahoo! Finance.

At any rate, the good news is that open source software is leading the way not only in panoramic picture creation, but in tiled image stitching, distortion correction, and perspective adjustment.

Click Here!