Wednesday, July 13, 2011

Hugin from scratch (for Windows 7)

One of the most powerful panorama stitching programs is freely available and (for the most part) easy to use.  This "tutorial" is a step-by-step guide on how to install Hugin and generate your first panorama.  There are several url's that will prove useful as you work with Hugin, and I list them here for convenience:
   http://hugin.sourceforge.net/ is the home page for the Hugin open-source project
   http://hugin.sourceforge.net/tutorials/index.shtml is the home page for various tutorials on how to use Hugin
   http://sourceforge.net/projects/hugin/files/hugin/hugin-2011.2_beta/ for those brave enough to want to try the very latest beta software.
I actually recommend that you do not use the beta software until you become familiar with the program.  I list it only because the following tutorial was done with the beta software.  The most recent stable version (available at the first link) is Hugin-2011.0.

What does Hugin do?  Primarily, it allows you to stitch together a large number of overlapping photographs to generate one single image.  In the extreme it allows images such as the following "spherical" panorama of the lobby of my local public library.


This panorama, reduced for this writeup, is 18,000 pixels wide and and consists of over 70 individual photographs!  Don't expect to be able to duplicate this type of work immediately, but with a little practice you will soon be generating some amazing images!

The best way to learn how to use the program is to just jump in and do it!  I have six images, show below, that I will stitch together to yield the panorama at the bottom.


Part 1.  Downloading and Installing Hugin
The safe way to proceed is to go to the Hugin sourceforge page (http://hugin.sourceforge.net/) and click on the link "Download".  From the download page go to the "Pre-compiled versions" and select the correct build for your computer (note that I am using the Windows 64-bit version--if you are using Mac or other platform there may be differences).  Download the proper version for your system and run it.

Keep in mind that minor (and sometimes major) changes can occur from one version to another.  The following screen saves are from the Hugin_2011.2.0-beta1-64bit_Windows release.  If you want the "cutting edge" software, try http://sourceforge.net/projects/hugin/files/hugin/.

When you run the setup software the first pop-up box will be:
Select "OK" and you will get:
I have found that checking the "Clean Registry Settings" box avoids some problems, so I always check it also.
You can decide if  you want shortcuts and documentation added.  Select "Next" and you will see:
Select "Next" and get:
Read the license (ha!) and select "I Agree":
Unless you know what you are doing, select "Install":
After a few seconds you should get:
Selecting "Next" yields:
Congratulations, you are ready to run Hugin!

Part 2.  Downloading test photos
If you wish to use the six shots shown earlier in this post you can get them in several ways.  

1) If you have a Flickr account search for images using the keyword "huggintest" (you probably have to create a free account to download the images).  They should be in "xraycrystallographers" photos.   

2) Another way to get the images is to download a zipped file that I have placed on the Slashtmp system at Indiana University.  Simply click on the following url and then enter the password "hugintest" when asked.  There are several freware programs available for unzipping the downloaded file.

Part 3. Creating the panorama
When you start Hugin you should get the startup user interface screen below.  Notice that a pop-up window with "Did you know" hints will appear over the window.  I leave this option on since there are many "secrets" of Hugin that I do not yet know.

After selecting "Close" in the hint window you can use the "File" tab to locate and open the files you want to stitch.  I prefer to open a second window with the images visible as thumbnails so that I can see which ones I want to input.  After selecting all of the desired images I simply "drag" them into the Hugin window:
After dragging the images into the user interface, you should see the following:
Notice under the "Load images" box it now states "6 images loaded".   You can click on the "Images" tab to see the names and sizes of the loaded images.  Before proceeding, I recommend that you click on each of other tabs under the toolbar to see what is available to the user (but don't worry about what these options do  at this stage).

You are now ready to create your panorama.  Simply click on "2. Align..."

A pop-up window will appear with a running commentary of the various processes that take place:


In a few minutes (or seconds or hours depending on the number of images and complexity) you will see a second popup box "Fast Panorama preview" appear. 
Expand this window either by selecting the full screen icon in the upper right or click and drag one of the corners to increase the size of the window.  You should get a screen similar to the following:
When I got to this point the image looked pretty good.  I wanted to play with some of the adjustments so to insure that I did not mess things up I selected "File" and "Save" to save the work I have already done.  A window will appear asking for the name of the ".pto" file to save.  This file will save everything that has been done up to this point.  If something goes wrong, I can simply restart Hugin and use "File" "Open" to get back to this stage.

While everything is working so far it might be worth looking at what one can do in the Fast Panorama preview screen.  One of the neater functions is "Layout".  If you select "Layout" you get the following:
Not only does this show which images are connected by "control points", it allows you to pick a pair of images to be examined in the "Control Point" tab by clicking on the line that joins the two images in question. For our example, let us go ahead and complete the panorama as it now stands.  Simply go back to the Hugin interace and select the "Stitcher" tab:
You will eventually want to learn about the various options available, but for now lets assume that we simply want to generate the final panorama as suggested.  You might want to change the format from Tiff to JPG depending on what you plan on doing with the output, but other than that, simply click on "Stitch". 

You will be asked for the name of the output file.  Enter a name and select "Save".  You will see one or two auxiliary screens open showing the stitching status.

When the panorama is complete the auxiliary windows will disappear and you can view your final result.


Part 4. Creating the panorama by steps
Hugin will generate excellent results for most "normal" situations, but occasionally something will go wrong.  For this reason you should learn to go through the various steps one at a time to see what their functions are.  After loading the six images, go to the "Images" tab and click on the "Create control points" box.  This will locate the control points that can be used to stitch the various photos.  You also have the option of using the "Control Points" tab to individually select the control points to be used, or to delete those that you don't want to use.  

After locating control points the "Optimizer" tab is used to overlay the images and the "Exposure" tab adjusts each image for proper exposure.  I suggest you simply play around with the various controls to see what they do.  If you save your work as a .pto file, you can always recover from a mistake.

Part 4. Understanding Hugin and its capabilities
There are some excellent tutorials available that explain in great detail the many different things you can do with the Hugin interface.You should take the time to read them so that you know what is available.  Don't be discouraged if things don't work as expected each time.  Hugin is a complex system constantly undergoing changes!

The main thing is ENJOY!

Saturday, January 8, 2011

It's fun to fool Mother Nature

One of the problems with modern computers and digital photography is that you can't trust any image!  The following is a photo that, on first inspection, appears to be a real snowflake  with five "spokes"!


Unfortunately, nature doesn't do this sort of thing!  Snowflakes are crystals of hexagonal ice, and are always of hexagonal symmetry.  You can read all about snowflakes by going to Kenneth Libbrecht's excellent site, SnowCrystals.com.

How did I do this?  It was actually quite fun, and the technique can probably be used to manipulate other images that have some sort of axial symmetry.  The following gives the step-by-step operations that were used to create the five-fold symmetry using PhotoShop CS5.

The original photograph was taken using my photomicrography setup for snowflakes*.   While one could spend quite a bit of time cleaning up this image, I purposely left it in a rather crude state so that it looked "real".
The next step is to accurately position the image in the center of a square frame.  There are probably many ways to accomplish this, but I first used the "Image/Canvas Size" instruction to make the image square.  I then used the Line Tool to create an "X" as shown in the image.
I then used the "Move Tool" (v) and moved the image until the snowflake was precisely centered.  It is wise to enlarge the image to 200% or higher to make the centering as accurate as possible.
The next step is to use the "Ruler Tool", followed by "Straighten" ( or "Image/Rotate/Arbitrary" in as in CS4) to insure that one of the spokes is vertical.
The next operation is to  use the "Filter/Distort/Polar Coordinates" tool, selecting the "Polar to Rectangular" option.  The resulting image will appear somewhat like the image shown.  You will find that the is terribly sensitive to where the center of the image is in the canvas.
The next step is to carefully remove one of the spokes by using the crop tool, and then again adjust the Canvas Size to make the image perfectly square again.
The above image is then converted back to a snowflake by using the "Rectangular to Polar" option in the "Filter/Distort/Polar Coordinates" tool.  (There is a bug in CS5 that tends to screw up the Polar Coordinate conversion--if it happens to you simply save the image above and restart CS5.)
You get your final image by cropping and cleaning up any slight imperfections such as the vertical seam seen above.







Once you have mastered the technique, you can create snowflakes with as many spokes as you wish!  Note that you can also make more perfect snowflakes by simply creating a line of "spokes" in a square frame and then converting to the snowflake using the Polar Distortion filter.  How about an 11 pointed snowflake?

Or a seven legged starfish?

___________________________________________________
*You can take a look at the microscope setup I use for photographing snowflakes at Xraycrystallographer.blogspot.