Last time, I told you how to use the fully-automatic mode of hugin, and how to make a few minor corrections to improve results. Today, we will look at more complex panoramas, and some more manual work in the program. Last time, the photos for our panorama were all at the same elevation, but at differing lateral angles – rotating the camera left and right, not up and down. This time, the photos will be in two rows, one higher up than the other.
Here‘s a small “PDF” with photos I hastily took at Arches National Park – rename the file to *.zip. The photos are at 1/25 size, to keep the file small, so please don’t expect a beautiful panorama as a result.
Simply toss the photos into hugin, use the auto alignment – always a good first option.
Let’s take a closer look at this panorama preview window. In the middle, we see the aligned photos – if you open the window before aligning via either the auto aligner or the ‘Optimizer’ tab, you see only the first photo smack in the center, as all others are directly under it. In this case, the panorama has been shifted high up; we’ll get to this in a minute.
On the top left you see various icons. Their names are pretty self-explanatory, and if you hover the mouse over them you get a short explanation. Play with them a bit.
Selecting and de-selecting photos
Below them, there are a number of boxes with numbers. These are the images, and if a box looks ‘pressed’ the image is active. Deselecting images here removes them from the final stitching, and also allows you to align the rest of the images via the ‘Optimizer’ tab: it has a check box ‘Only use control points between image selected in preview window’. Neat!
Obviously, in this case we want to use all images, right? But if you took very many images it is sometimes possible to make do with fewer. That saves calculation time, but it also means that your final image will be computed from fewer images overlaying each other, which can increase the resolution. [You can additionally use masks to protect certain areas from being combined from several photos, to make sure the stitching process doesn’t ruin them by blanking out or washing out highlights, or pixelating gridded surfaces (Eli, this is for you!)] Click on the boxes to see what the panorama preview looks like when you remove photos. You will quickly find out that given the currently suggested crop (the rectangle that is not toned down) you can drop photos 8 and 9, but not 10!
By the way, the situation where this selecting photos becomes important is if you have a lot of people running through your view all the time while taking the photos and you’re too lazy to mask them all out. Even more important: you can use bad photos (totally underexposed, even blurry) to align, then remove them in the preview and have their bad quality not influence the final stitched panorama. But hey, we’re all perfect photographers who never take bad photos, so we’re never gonna need this 😉
Now, next step it to get the most panorama out of the aligned photos, and un-distort the picture, too. You can do this by resetting the center, rotating the image, and by selecting different projection modes. I’ve gone over this very briefly before, now is the time to detail things a bit more
Projection modes and aligning the panorama
Projection modes are important because we are trying to show a sphere on a 2D surface, and there are many different options how you can do that. Ideally, you’d get a mode where all angles are the same as they are on the sphere, and where all distances are the same, too. The problem is that this is impossible, unless you actually use a sphere for your canvas. Cartographers have fought this issue since the first guy realised that the world is not flat. Depending on what the map was intended for, they found options that either kept angles OK, or distances, or compromised by inducing errors in both. Many projection modes create the largest distortions at the edges – i.e., the further you go from the center of the image, the bigger the mess. Typical World Maps, centered on the equator show grossly East-West stretched Arctic and Antarctic regions, less stretched middle latitudes, and a fairly undistorted equatorial region – which is why Greenland looks nearly as big as Africa on them. Such a projection is OK if you’re mostly interested in the equatorial and middle latitudes, but utterly useless for navigating the Bering Sea.
Of the man modes of projection hugin knows, some are especially useful for certain types of panoramas. I usually only make sue of three modes in hugin, because of the types of panoramas I shoot.
This mode is usually the best choice for single-row panoramas. You get moderate distortion at the top and bottom of the image, but the middle part is unaffected. That’s the mentioned typical world map thingy. If you image is very wide but not very high, you’re fine. If it is really only one row high, the distortion is the same as you get in one photo!
This mode is what a pinhole camera does: project everything through one point where the flat surface of the picture “touches” the sphere. It is a very good mode for panoramas that do not cover very wide angles – say 100° – in either width or height. Your average DSLR lens will typically be very close to this projection mode, unless it is a superzoom or fisheye. An enormous advantage of the rectilinear projection is that straight lines remain straight! Very good for photos of objects with obvious vanishing points! Sometimes, it is better to go with a smaller part of the panorama you so assiduously shot the photos for, cutting away a large frame and sticking with rectilinear projection, than using a different projection mode and getting curvy lines all over the building you photographed.
Equirectangular projection is mathematically the easiest projection mode: the horizontal position of a point is simply its longitude on the sphere, and the vertical position is its latitude, with no scaling or transformation. This makes for very strange images when you print out a 360° panorama! A really good thing is that equirectangular projection preserves the vertical, and that the horizon is a horizontal line at the center of the image. I use this projection a lot for images that are too high for cylindrical projection, and wide enough to give trouble with rectilinear projection. Essentially, if you fiddle enough with the center position, you get a good tradeoff between distortion along the edges and distortion of straight lines.
OK, let’s see what these do to the panorama – but first we should alter the presentation a bit to make the panorama preview use the full width of the screen. To the right and below the preview there are sliders that alter the field of view. Use these and a left-click into the center of the picture to get the preview to fill the screen:
Now alter the position of the center point by left-clicking higher or lower than it is currently located. You may need to go to the ‘Stitcher’ tab and ‘Calculate field of view’ after each change. It quickly becomes apparent that the initially suggested center point wasn’t half bad: the contact between the massive and the layered rocks is fairly straight, and by having the center of the projection way below the picture you get a panorama with little distortion.
In this case, a equirectangular projection works well, whereas a rectilinear one results either in horribly distorted tops of the rocks or a very obvious bending of the picture.
Once the picture looks as little distorted as you can make it, the next step is to rotate it (if necessary – right-click a point to move it to the horizontal). Then, decide on the crop – or just stitch everything and do further editing in you favourite graphics editing program. In order to edit the crop in hugin you need to enter pixel values into the four fields provided in the ‘Stitcher’ tab; they refer to the top left corner. Simply change a number, then click somewhere else and the new value is applied in the panorama preview.
Here’s what I arrived at after some playing:
OK, what if there are any problem?
Insufficient control points
Sometimes, when you check out your final panorama, you find areas where the photos are stitched wrong. That’s usually because there are insufficient control points between overlapping photos – usually photos that overlap too little – and thus hugin throws things together so that steps occur in what really should be straight lines, and so on.
First of, check if there are indeed image pairs that overlap and have no or few control points between them. To do that, open the Fast Panorama Preview. You can find an icon for it in the main window, it says ‘GL’ on it. “Fast” suggests that it does less than the preview you already know – in fact, it does a lot more! You can set hugin to open either of the two as a standard option.
Go to the ‘Layout’ tab of the Fast Panorama Preview. Here, you get a map of how images are arranged and connected. The coloured lines show you how many control points there are between overlapping images. You can simply click a line that indicated few or no control points, and hugin’s main window will show the two photos concerned in the ‘Control points’ tab. Here, you can either add CPs manually, or you remember the two image numbers, go to the ‘Images’ tab, select the photos, and have hugin find control points via the ‘Creat control points’ button. it’s worth trying this, especially when you up the number of control points hugin is supposed to look for by increasing the number in the ‘Points per overlap’ field. I usually type in 25 or so at this step.
If this doesn’t work, you must add the CPs manually. You can do this by simply clicking into one of the two photos in the ‘Control points’ tab, then on the same point in the other. There’s zoom settings to make this task easier. If you leave the boxes ‘auto fine-tune’ and ‘auto-add’ checked, and if hugin agrees that the two points match, the CP is automatically added. If not, you will need to click ‘Add’ to overrule hugin.
Once you have added a few CPs hugin will usually get very good at auto adding more, but do check each pair if it is correct! Similarly, if you have a lot of CPs between photos and the alignment still sucks, you should check that hugin hasn’t fallen for repetitive structures in the images and misaligned CPs.
This view of two images in the ‘Control points’ tab shows 20 control points, the mentioned buttons, and the control point list at the bottom. As you can see, the CPs are well-spread over the overlap, which guarantees good stitching. They are also all listed as ‘normal’, meaning that they serve to align two images to each other. There’s other types of alignment that I will get to later, e.g. for telling hugin what is a horizontal line (for removing distortion).
Masking away small mis-stiches and people
Sometimes, hugin stitches areas from the wrong photos, in which the area concerned is at the very edge and thus much distorted, because these photos are high up in the stack (have low image numbers). You can simply mask away these areas. Go to the ‘Mask’ tab and select the image you want NOT used, then draw a mask on the photo. Or, select the one you WANT used, and select ‘include region’ as the mask type. Either way is fine. This is the best way to get rid of people in your photos, or other moving things. Or, if you’re into that, you can make multiple positions of one object shown this way, too, by masking out the photos that show empty background, and keeping the object or person in.
Masks can be copied and pasted from one photo to another, too – very helpful if you have a serious of photos with that stupid tourist standing in the very same place nearly all the time. Because the shape of the mask you need will barely vary between photos you can simply c&p, then adjust position. Remember, however, to check the panorama preview: if you use too many masks you create gaps in your final output!
Sometimes, if the optimization of alignment really sucks, it is a good idea to run an optimization for position only first, then check the Fast Panorama Preview for images pairs that have insufficient CPs between them, and only later go for the full Monty of ‘position, view and barrel’. It can also help to re-set the anchor image – that’s where hugin starts aligning. Go to the ‘Images’ tab, select a photo in the center of the intended panorama, and make it the anchor for alignment by clicking ‘Anchor this image for position’ at the bottom left. Below it is the same command for exposure – if you have images with very different exposures you can here tell hugin which one to use as the template for the final stitch. I may go into that later in detail.
If this approach to optimization doesn’t work well I usually try removing images from the alignment and final panorama. Often, that’s the quickest way to avoid stitching errors. Also, it may tell me which images have CPs that are wrong – I can then go and manually adjust them by moving them into the correct position in the ‘Control points’ tab.
I guess this is enough for now. If you have any questions do ask in comments!