Stitching Panorama Photos in Linux and Unix

I have been casually searching for a good way to create panorama photos out of several individual shots for a little while now. I've read other articles and seen half a dozen projects for doing this. I had been turned off by some of the others because they required Sun's Java to be installed, others were in early beta status, and others were windows programs run with emulation on Linux/Unix. I finally stumbled upon a great tool for what I was looking to do. It runs natively on Linux/Unix, does not need Java, and follows the old Unix idea of doing one job and doing it well. It is called "xmerge" and can be found here: http://xmerge.sourceforge.net/

It is important to read it's Readme file, especially the section that talks about the in-program key funtions: http://xmerge.sourceforge.net/readme.html. In this Howto I'll walk through all of my steps from selecting the original images to the final panorama version.

Items to be used:


Step 1: Resave .jpg images to .ppm format


This step is simple enough. Xmerge works with .ppm files, so in any way you like, you can resave your .jpg files to .ppm. The way that I did it is I used The GIMP to open each sunsetX.jpg file, did a File -> Save As... then in the Save dialog box, set the "Determine File Type" dropdown to "By Extension", and I give the file a .ppm extension and save. It will then ask if you want to save the .ppm in "RAW" or "ASCII" format, I chose "RAW". After you are done resaving each of the 5 photos to a .ppm format we move to Step 2.

Step 2: Open all 5 photos in xmerge together


Currently this step is done using the command line. Open any terminal you like (Eterm, xterm, rxvt, konsole, etc) and move to the directory where you have the 5 sunsetX.ppm files saved (ex: $ cd ~/myPhotos). I have xmerge in /usr/bin, so I execute a command something like:

$ xmerge -o sunset_pan.ppm sunset5.ppm sunset4.ppm sunset3.ppm sunset2.ppm sunset1.ppm

to open xmerge with the 5 photos to be stitched together into your panorama. The "-o sunset_pan.ppm" as you might guess is the output file name, followed by the names of all 5 photos in the order from leftmost photo to rightmost photo that you want to be stitched.

After this command xmerge will open showing the 5 photos in a row. Time for Step 3.

Step 3: Selecting common reference points for stitching


Now it is time to select the common points of the overlapping shots so that xmerge can stitch the shots together as seamlessly as possible. As mentioned in the Readme.html file linked to above, you can use the "+" and "-" keys to zoom in and out on the photos. The middle mouse button, or wheel in my case, (or even clicking left and right button simultaneously with "3rd mouse button emulation" enabled) is how you can scroll around the photos.

I maximized the xmerge window, centered the photos, then zoomed in a few times with "+". Clicking my way over to the border between photos 1 and 2 with my middle mouse button, I look at the overlapping border for these shots and select an area that is easily identifiable in the photo directly to the left. In this case I choose the small dip that they both show. I click one time to start the creation of the selection box, then move the mouse to the bottom right of the dip and click again to finish the selection.

I am then presented with a small clip out of the area I just selected. I then move my mouse over to the photo directly to the left and very carefully place the piece directly on top of the dip in this photo and click to mark the reference point.


This same process needs to be repeated to give a stitching reference point for each adjacent photo pair. Using the middle mouse button I move over to the next border between shots 2 and 3. Here I select the small bump on the ridge seen in both shots. I place my clipped piece over the bump in photo 3 and click to mark the point.


For the reference between photo 3 and 4, I chose this bump.


For the reference between photo 4 and 5, I chose these clouds and the peak.


After the reference points have been chosen it is time to proceed to Step 4.

Step 4: Stitch the photos together


In the readme file it states that the "s" key will initiate the stitching of the photos together. Since we have our reference points selected, hit the "s" key. You will see that the images become overlapped on their reference points now.


Hit the "w" key to write out the rough panorama photo. After a 5-10 seconds of writing this out, you can hit "q" to quit xmerge. Now it is time to use The GIMP to polish off this shot for it's final version in Step 5.

Step 5: Final touches


Start The GIMP (or other graphics program) and open the file sunset_pan.ppm. You can see that the photos were shifted vertically as well as horizontally to get the reference points to line up. A bright red fills any background space left void after the shift. We want to crop out the rough edges of the shot for our final image.


Use the rectangle select tool ("r" activates this tool) and draw a square around just the area that you want to keep. Then copy this selection, create a new blank file with the selected area's new width and height (gimp auto fills the height and width for the new shot with the dimensions of the copied area), and then paste your selection into the new file. You can now save this file as a more universal image format like .jpg or whatever you like. I also resized this panorama so that it is can be viewed on a monitor set to 1280x1024 resolution.

I made one more quick modification to the image for my final shot. In Image -> Layer -> Colors -> Levels I chose the Blue channel and modified the middle value of 1.00 to 1.40 which pumped up the blue in the sky and gave a nice pink to the clouds. One more save and we are done.

Afterword


These 5 original photos used here were taken just before I learned about taking shots for panoramic photos. The biggest mistake that I made was letting the camera auto expose for each seperate shot. You can see the slight differences accross the blue in the sky from left to right.

Now that I have a fully manual camera, I can just set it to manual, adjust the shutter speed and f-stop to fixed values that I can use for each of the 5 shots. On a more basic point-and-shoot style camera that does not have the option of manually setting these, you can use a common subject to force the same exposure for each photo. For example you could place one of the clouds in the exact middle of your shot, depress the shutter button half way to trigger the auto exposure, then recompose the shot of the area you want in this photo, and press the shutter button the 2nd half to capture the photo. Then for the rest of the photos, target the exact same cloud, half depress the shutter button again to calculate exposure, then take your next shot. This will eliminate the different exposures ranging across the final panorama shot.

Here is my final panorama created by following these instructions:
Final Panorama

I hope you found this tutorial informative and useful. If you have any questions or comments about it, please contact me at: