Creating Panorama pictures or: “The power of open source software”

31. August 2008

First, a little disclaimer:

I am not a good photographer. All I know is that longer shutter values give more light, so does a wider aperture. That’s it.

I do not own a good camera. It even isn’t a SLR. It is so old, is sucessor already has a sucessor.

Despite these more than obvious limitations, I managed to create some decent looking shots, all with the help of the above mentioned equipment and open source software.

Cathedral in Palma de Mallorca

In particular, I am talking about:

Hugin - the panorama stitcher. To me, hugin is one of the greatest pieces of F(L)OSS to date. It builds on extremely powerfull tools which feature heavy mathematics and insanely clever algorithms that are way over my head, yet it gives me the power to use these tools to create results that leave my viewers with dropped jars. And all of this with no more than 4 dialogs, each of which as easy as browsing the web.

Gimp - Gimp probably does not need an introduction. The Title says it all: GNU Image Manipulation Program. Nothing more, nothing less. In this tutorial I will only use a very small function of Gimp’s features:

  • automatic color adjustment
  • selecting and cropping a rectangular area out of a picture and setting the selection as the new canvas
  • the incredible lomo plugin

Phatch - Photo batch processing. Although not exactly needed for panorama creation, it still makes my list of the must-have applications for image processing. It’s features include almost every common task in (mass) image processing. What makes it a killer for me is:

  • it’s power. Almost nothing you do on a lot of images that can’t be automated here
  • it’s style. Beautiful icons as well as ui. It matters
  • it’s reusability. Create a sequence of actions once and then apply them over and over again.

The Start

It starts with the pictures. This is the most important steps. If you do well here, the rest of the steps will go like clockwork. If you do badly here, the rest will be a neverending pain and the result will not be satisfying. So what are the cornerstones of a good set of pictures for a panorama?

Not too close focus. If you focus on something that is not very far away from the point you shoot, you run into a problem of perspective when stitching the photos. The result will be that your image will be far from rectangular but some sort of rainbow shape. That is why it is extremely difficuilt to shoot a panorama from, let’s say, your room. It is not impossible, only I didn’t manage it yet.

Constant camera parameters. When shooting panoramas, you shoot most parts of the scenary more than once. But if you have the camera on an automatic adjustment mode, the parameters of aperture and shutter will adjust each time you move the camera, resulting in different shots of the same area. Although Hugin has a great enblending feature that tries to adjust the images, it cannot do miracles. If you have pictures with different gamma, you will have soft edges instead of hard ones, but you will have edges and edges kill the feeling of the panorama beeing a single picture.

Constant horizon. As stupid as it may sound: This one is important! Prior to shooting your pictures, you have to think about the horizon line of your panaroama. By horizon line I mean the middle line of your picture. It should be a straight line that is parallel to the natural horizon. If you mess this up, you will loose much quality, at best.

Here are the step-by-step instructions to shooting a panroama set of pictures:

  1. Set the camera to landscape mode and let it adjust to what you think to be a median point of your scene in terms of exposure
  2. remember the values the camera chose for shutter and aperture, switch to manual mode and enter these values
  3. scan the whole scene and watch the exposure indication
  4. reflect what your shutter and aperture values mean for the resulting images. Which parts do you want to be the best exposed? Which parts can be over/under exposed?
  5. Adjust shutter and aperture. Switch back to 4. until you are satisfied
  6. shoot images with an overlap of ~30%-40% without moving. Let the autofocus of the camera adjust to every image, this does not affect the resulting exposure.

In the end your pictures could look something like this:

Stitching

Now go back to your lab and launch Hugin.

Now, Hugin is very powerful. Over at their site, there are wonderful tutorials, docu and tech explanations. So I won’t even try to get into that. I will use Hugin to do the following:

  1. Load the images
  2. Set a position and light anchor
  3. Set control points (i.e. points in the pictures that occur in more than one image). This can be done via an assistant, more about this soon.
  4. Optimize the images according to these control points
  5. Preview the output
  6. set the parameters of the resulting panorama
  7. Stitch and blend the beast

A Note about the hugin version:

The current version in the hardy repos is 0.7b4. This version works fine for me. I encounter one bug from time to time: When you resize the image preview panels in the control point area, sometimes the images vanish, leaving you with a gray widget. Don’t panic, just save your project, exit hugin and start it again.

At the time of writing, hugin version 0.7rc2 has been released. It has much more features than 0.7b4. It can do “exposure fusion” and “HDR”. I do not exactly understand what this is, and the changelog isn’t of much help to me. In fact, I never used them. Who wants to be at the bleeding edge or use those new features, there is an excellent compilation howto at the pantotools wiki. I followed the steps there and everything worked out of the box. But be prepared to install a decent pile of packages, check out several projects vom versioning systems and compile for … quite some time.

The Assistant

Hugin offers an assistant that guides you through the creation process like windows installers do. I prefer to do the manual round as I have more control about what happens and what happens when. So the Starting point for me is the files dialog:

Here we add the files involved in our panorama. Make sure the files are in the correct ordering or add them in the correct order. Then select the middle image and make it an anchor for both position and light.

Autopano

Now you are at a turning point. You can autopano make search for control points, or set them manually.

The advantages of autopano:

  • It compares every pair of input images, not just adjacent pairs. You will get alot of control points if you shot with enough overlay.
  • It finds control points where the human eye would not. Imagine you shot a forest or something like that, you are out of luck. Hugin is not. I think each image gets transformed into a (huge) set of defining points and these “graphs” are than scanned for simuliarities. This method does not fail.

The disadvantages of autopano:

  • It’s slow. This is not exaclty true. Compared to what it does, it is super fast. But what it does is really time consuming. Also, it’s time growth is O(n²) if n is the amount of pictures, as it searches every pair (I am just assuming it is like that, I do not know for sure and would be delighted to get a comment if I am wrong).
  • Its choice of points lacks human intuition. Now how can that be a disadvantage? When you set points manually, you put some brain in your choice. You choose the points carefully in order to make them good points, autopano cannot do that. It just searches for points (using whatever algorithm) until it has found as many as you told it to find and moves on.

Control Points

So what makes a control point a good control point?

  • Focus. Try to chose points that are in your focus area. I you shoot a house 20m away from you, don’t pick a TV-tower 5km into the city. If you shoot a mountain line, don’t pick a car on the parking lot you are standing on
  • Perspective. Try to chose points that are significant indicators of perspective. Edges of buildings are good. Corners of windows are good. But be aware that a point is not a point in the mathematical sense of the word (i.e. a circle with radius 0), but rather a smal area. So if you chose an edge of a house, but behind that house is another house which is 50m behind the one you chose, make sure that your point does not include the second house. If it does, you confuse the software, because if you move your camera (or even worse, yourself) the 2 points will shift differently.
  • Sufficiency. Try to chose points that cover your whole scenary. Try to chose points from the corners of the individual images and use the same point again in the next pair.

My experience is that it is not necessarily better to define many points. While control points are absolutely vital to the functionality of hugin, each control point constrains the stitching and blending tools in their ability to produce the best results. Chose 3-5 control points that match the criteria above. Do not chose control points near “critcal” areas, such as people or moving cars. These areas will look best in the outcome if the tools did not have to maintain on e of these points, but could produce the best picture.

Optimization

When you are done with your control points. It is time to lay your fate in the hands of hugin. Again, I habe no clue what is really going on under the hood, but I think the optimization step works like this:

With the defined control points, the images are “pinned” together at these points. Of course, this will not work exactly. The world is 3D, a photo 2D. So what hugin does is paint the image on the skin of an imaginary ball and adjust the parameters until the points are as close as possible. The outcome of this process is shown to you when you press “optimzie now” in the optimization panel:

These values show the distances between the control points after the optimization. You get an average, a maximum and a variance. To understand these values you have to have some basic statistic knowledge. If your average is low, but you have a high max (e.g. average = 1, max = 10) then you most probably chose one bad point. If you have a high variance, you screwed up. Generally speaking, everything under 1 is superb ( 1 think this are pixels, so everything under 1 is .. hardly existant), single points with an error < 10 can be corrected, but everything wors will not work.

After the optimization, you will see the optimized values for yaw, pitch and roll in the optimization pane. Also, If you go back to the control points, you now see the error of each point displayed. In that way, you can rework bad ones, keep good ones and optimize again.

When you are done, have a look at the preview:

Now this already looks really good. You can do alot of thing here, like adjusting viewpoints and whatsoever. I never used them so far.

Actual Stitch

Now, finally on to the Stitching pane:

Here you leave the projection as equirectangular, your stitcher is nona, enblend does your blending and you want to produce one tiff file with soft enblending enabled. Actually, I don’t know if you want to do that, but that’s what I use for this tutorial and in normal use. Push the compute angle/size buttons once and … stitch them together. The result will be one big tiff file, containing our panorama as well as some transparent space.

Gimp

Let’s open it in Gimp for processing:

Use the rectangular mask tool to mark the area of the image you want to keep. Then select Image -> reduce to selection (I am just guessing the englisch names here). You could also ctrl-x and insert as new image, but that would mean gimp has to move your selection to the clipboard and then create a new file with about the same size as our tiff. If the panorama is large, this uses alot of time and space if it not locks up your PC (depending on RAM, of course). So the cropped image should look something like this:

The next step is magic to me. My camera is not very good at capturing to real colors, a SLR camera does this much better and the images get not imporved very much by this step, but with my images this is a massive improvement. Open colors -> values. This brings up a dialog where you can adjust the range of the values for colors. It has an “automatic” button which pricudes very good results on images shot with my camera. If your camera is already good, you won’t see so much improvement here. In this dialog you can also generally lighten or darken your image. Beneath the historgram are 2 triangles. They represent the dark and light end of the scheme. If you move one of them all colors will be lighten up (or darkened).

Now it is time to save the image, because the stuf I do afterwards is of questionable taste and sometimes makes the images look fake. Usually I overwrite the tiff image produced by hugin because I see no point in maintaining the huge and bulky image.

Next is the lomo filter. In the comments of the page it describes lomo:

“Technically, this plugin creates a vignetting effect, it darkens the edges and brightens the center, while increasing the contrast of the image.”

One has to understand this in order to predict the effect of this filter. The center will be lighter, the edges will be darker. The contrast will be higher. What this means is that eg the clouds in the sky will vanish, if the focus of your image is not in the center (like when doing a groupfoto), the people on the border will become darker. You have 2 ways to influence how the plugin works. You can select the area it shall be applied to and you can adjust the 3 parameters of the plugin. You can find the filter at “Filter -> Light and shadow -> lomo”, once you copied the scm file to ~/.gimp-2.4/scripts/ and restarted gimp.

To apply the filter just to one area, simply use the various selection tools to select the area of your choice and run the filter. You have to bear in mind that the current selection will act as the total image for lomo. So if you select only your center area, lomo will treat this as a full canvas and make the border of it darker and the center lighter. As for the filter options:

Vignetting softness indicates how soft the vignette will be. If you wish a higher concentration in the centre, chose a higher value. A lower value will treat the whole area more equally.

Saturation is the general strength of the filter. Adjust to fit your level.

Contrast is the level of differences the filter will create.

As a rule of thumb: If you want a softer effect increase the softness and lower both the saturation and contrast (I always have the same values for saturation and contrast as changing only one does not have much impact). This is our sample images after lomo:

To describe the effect with my own words: it looks like a grey fog has been pulled off the image. On the downside, the sky looks now almost entirely white, creating a non-realistic scenary. So let’s do it again without the sky. To do so, select the sky with the wand and invert the selection and repeat the filter.

Now the sky looks the same as before and the foreground has been “enhanced”.

Phatch

There is not much value in editing one single photo with a batch processor and the focus of this tutorial really is the panorama stuff, so I will not get dirty with phatch right here. There is a great tutorial in their wiki to get started.

Closing notes

As you may have noticed during reading, I am not an expert in any of the domains covered here. I just wanted to share my personal experience and learning curve with anyone interested. That beeing said, it directly follows that I have made many mistakes througout the tutorial. If you spot one, please leave a comment. Thank you.

The process described above is just one (pretty standard) way to process your pictures. There are countless variations. Hugin alone offers dozen. You can play with viewpoints or the new blending methods if you dare to compile 0.7rc2 (which you should). Just one example that has happened quite a few times to me.

The Problem: You have a person, car or other moving object on your series of shots which is in different states in different pictures. You can try to leave as much power to hugin by not setting control points near the area, and very often hugin succeeds in sorting out which one to take and which one to overwrite. But sometimes you will not be satisfied. Or the same usecase: You have something/someone in one photo but not in the other and hugin keeps deleting it.

The solution: Order hugin to make not one tiff, but a multilayered tiff. This will result in an even larger file, but if you open it with gimp every of your input images will be fully intact (with the transformations done by hugin) and stored in one dedicated layer. What you can do now is erase an area in one layer to let the one below shine through. Feel free to exploit all the power of gimps tools.

Eclipse 3.4 Ganymede

19. August 2008

The current version of eclipse is 3.4, codename ganymede. The current version in the hardy repositories is 3.2. Version 3.4 has been marked as a candidate for Intrepid, so there is a chance the version in the repos will be updated some time in the not too distant future. On the same side of the argument, you can easily download and use any version of the eclipse IDE on you system. Just download the archive, extract it and run. You only need to setup your java environment properly. Some people even argue that there is no need for an eclipse package at all because of this.

However, I like the confort of installing software from a repo. It gives me the possibility of clean removal, automated updates and alle the other goodies that come with paket management.

Now, there might be reasons to prefer 3.4 over 3.2. In which case I would prefer a package over an archive. My search is over. I discovered this ppa of the launchpad eclipse team which contains a hardy package for 3.4.

I agree that the reasons for upgrading from 3.2 to 3.4 are not strong ones ( I develop happily with 3.2, but on the other hand, I probably use about 0,1% of eclipse’s features), and the basis for installing eclipse via apt is weak if existant, BUT if you want to, you can use the ppa.

sudo !!

07. August 2008

A friend of mine just told me this cool gadget:

How often do you type a command and realize you should have put sudo in front of that? I cannot count how often this has happened to me. But the next time I will be gratefull, because then I can just hammer sudo !! after the system told me that I do not have permission, and it will do. In slow motion:

sudo apt-get install foo

is the same as typing

apt-get install foo
sudo !!

(assuming you are not root…).

This is one more step towards “Do what I mean, not what I say!”

[Update] This keeps getting cooler. Thanks to bdam I know now that !$ references the last location, and !! references the last command. So the use of !! is not limited to sudo. Use it with rm oder cd …

How to get a clean install of Kubuntu with KDE 4.1

06. August 2008

KDE 4.1 logo

With the 4.1 release of the K Desktop Environment, the development team has taken KDE 4 to the level where it is suitable for the end user. Of course it still has his flaws, but the new technology is really neat.

When I wanted to test the new release, I did an installation roughly the same as outlined in this post by tombuntu. However one thing keeps bugging me:

  • The resulting system is kinda mixed up with KDE and Gnome. This is a problem with all dual installations. You either end up using many Gnome programs on KDE or vice versa. The alternative is to install many programs, which I am also not a big fan of. Everybody tries to keep his/her system as clean as possible.

I overcame this problem by installing KDE 4.1 from a fresh Ubuntu 8.04 Server installation. If you have your home directory on a seperate partition (which I would strongly advise), this is really simple. If you do not have this, there are many tutorials on how to do this on the net (Example).

  1. Clean up your home partition. This step helps ensure that you don’t carry around unnecessary data and application settings from previous installs, while on the other hand maintaining the application settings you want to keep (like firefox profiles, pidgin accounts, ssh keys …). To do so, log out of your session, switch to the console and create a temporary directory (eg. ~/backup). Then, go to your home directory
    cd
    and type
    cd . When you now hit tab multiple times you get a list of items in your home directory starting with a “.”. Identify the items you want to keep and move/copy them to your backup folder
    mv .mozilla backup/. Repeat this step until the backup folder contains only the personal settings that you want to keep. When you are done, remove everything starting with a dot from your home directory (remember to be logged out and do not login after this until you did your install)

    rm -r .*

    You can add the -f switch if you are really sure what you are doing. You don’t have to worry about . or .., those will not be affected, but rm -rf is a dangerous command. Now that your home is wiped clean, copy the backup and optionally remove it.
    cd backup
    mv .* ../
    cd ..
    rm -r backup

  2. Now to the real stuff. Donwload and burn the 8.04 LTS Server image from here. Insert the CD and boot. When partitioning during the install, be sure to set your old home partition as the new one without installing the file system. Further reading on partitions could start here (beware, german).
  3. After finishing the install, boot, login, update and upgrade your system to the latest patchlevel. You probably don’t want to keep the server kernel, so install linux-image-generic or any kernel of your choice. Remeber to edit the menu.lst to set your default booting kernel. It is important that you reboot, update and upgrade again when you installed the new kernel.
  4. Now we are ready to bring the bling. Add
    deb http://ppa.launchpad.net/kubuntu-members-kde4/ubuntu hardy main

    to your sources.list with sudo nano /etc/apt/sources.list.Install the following packages

    sudo apt-get install kubuntu-kde4-desktop gtk-qt-engine-kde4

    and after the next reboot you should be greeted by a clean, fresh KDE 4.1 login screen.

Wenn man bei der Freundin ein neues DSL eingerichtet hat…

27. Juli 2008
wenn-man-bei-der-freundin-ein-neues-dsl-eingerichtet-hat

… dann is die Arbeit noch lange net rum! Denn: Outlook versendet keine Emails. Die DB Seite geht net. Und beim Telefonieren hört man immer ein Besetztzeichen im Hintergrund.

Wäre mir jemand vor 5 Jahren mit den Symptomen gekommen, hätte ich sofort gebrüllt: M    T    U !!! Heute hat das bei mir ein paar Wochen gedauert bis ich drauf kam. Ich weiß nichtmal, ob das ein Windows spezifisches Problem is oder ob mir das mit *buntu genauso gegangen wäre.

Auf jeden Fall ist die Ursache, dass jetzt die FritzBox! von 1&1 nix anderes mehr macht als ein WLAN herzustellen und alle Packete über eine Standardroute an das Alice Kästchen weiterzureichen. Dummerweise muss es dabei noch irgendeinen Header draufpacken! Wieso, warum, und welchen bleibt sein Geheimnis. Da ich persönlich jetzt nicht die höchste Meinung von der verwendeten Hardware habe (hatte), hab ich ein solches Infrastrukturproblem nicht gleich in Betracht gezogen. Aber dann habe ich mangels weiterer Ideen Wireshark installiert und siehe da, der Fehler wurde mir auf dem Silbertablet vom ICMP geliefert. “Fragmentation needed”. Der Fall war klar. Wenn man soviel Nutzlast auf ein zusendendes Packet legt, dass es Fragmentiert werden muss, so wird das Packet maximal groß. Mit zum zusätzlichen Header ZU groß. Flugs die MTU auf 1454 runtergesetzt (Google hilft hier) und schon lassen sich wieder Emails versenden, und meine Hattrick Pressemitteilung ging auf einmal auch raus.

Und nicht nur das. Das Besetztzeichen is weg. Ich bin der Held. Aber wieso?? Ich meine okay, es is Internettelefonie über das selbe AID, welches die Packete droppen musste. Aber wieso ertönt deshalb ein Besetztzeichen… ich hab ja nur auf einem Client Rechner die MTU geändert. Die Telefone hängen ja auch direkt an dem AID, die wissen netmal, dass es da noch ein WLAN mit potentiellen Packetgrößenproblemen gibt. Sicherlich interessant, ob Alice das weiß…

Wenn man der Freundin ein neues DSL einrichten will…

08. Juli 2008
wenn-man-der-freundin-ein-neues-dsl-einrichten-will

… dann ist das natürlich eines dieser neuen Angebote, bei denen man keinen Telekom Anschluss mehr braucht. Was das in Geek-Sprache heißt ist, dass es keine Telefonleitung mehr gibt, sondern die Telefongespräche per VoIP geführt werden.

Was das ganze ein wenig interessant macht, ist die Tatsache dass der bisher in Betrieb gewesene WLAN Router des Vorgänger ISPs weiterverwendet werden soll, da man sich die 30€ für den WLAN Router von Alice spart. Für den Freund heisst dass, dass er dem 1&1 WLAN Router beibringen muss, dass er jetzt kein DHCP mehr macht, sondern brav routed was kommt. Ich will jetzt nicht die Details ausweiden, aber ich muss sagen, dass man so einem 1&1 Router so einiges beibringen kann. Einen Moment gebraucht habe ich bei der Einrichtung einer default Route zu dem neuen Standardgateway. Unter dem Menupunkt “statische Routen” kann man eine Maske aus “Netzwerk, Subnetzmaske und Gateway” ausfüllen. Nur was tragen wir da jetzt ein? Gateway is klar. Aber die anderen beiden?? Es soll immer und für jede IP gerouted werden. Welche IP Adressen sind alle? Aus der Rechnernetze Vorlesung ist hängengeblieben, das 255.255.255.255 Broadcast ist. Broadcast sind alle möglichen Empfänger, was was vollkommen anderes is als alle IP Adressen. Würde man das da eintragen, so würde man nur Broadcasts routen. Nicht gut. In meiner Verzweiflung habe ich als Netz 0.0.0.0 eingegeben. Beim Drücken des Übernehmen Knopfes erhalte ich eine Fehlermeldung:

Beim Einrichten einer Defaultroute müssen sowohl Subnetzmaske als auch Netzwerk 0.0.0.0 sein.

Aha. So geht das also. Wieso muss ich das per Fehlermeldung erfahren? Hätte ich das wissen müssen? Meine Freundin hat schon die ganze Zeit gesagt: “Wenn noch nichtmal DU das kannst…”. Jetzt ist dieser Ausspruch ganz klar als Kritik an den Installationsroutinen der heutigen ISPs zu verstehen. In die selbe Kerbe schlägt der Spruch: “Die können zum Mond fliegen aber nicht XYZ so machen, dass jeder normale Mensch es bedienen kann!”.

Ihr Ausspruch baut aber gewissermaßen ein wenig Druck auf. Was ist, wenn ich es nicht schaffe, diese Hardwaremigration abzuwickeln. Habe ich dann als IT Fachmann versagt? Hier steht auch ein Teil der Männlichkeit auf dem Spiel.

Die eigentliche DSL Installation ist schnell erzählt, denn das Modem erhielt ein DSL Signal. Punkt. Weiter gehts mit Telefon. Das Lämpchen am Modem leuchtet zuerst Rot, was für Softwareupdate steht und dann Gelb, was für “OK” steht. Soweit sogut. Analoge Endgeräte anschließen. Hörer Abheben. Komisches Besetztzeichen. Kein Erfolg. Und die Aussicht am nächsten Morgen mit dem First Level Support zu telefonieren.

Das Telefonat mit dem FLS ist schnell vorbei, denn erfrischend schnell hat der Kollege erkannt, das das keine HowTo Frage ist, sondern ein Fall für den Second Level Support. Zu früh gefreut, denn nach 20 Sekunden Gespräch ist klar, dass der ISDN Tarif gebucht ist, und deshalb keine Analogen Endgeräte ohne A/B Wandler an das IAD angeschlossen werden dürfen. Jedes Kind weiß das.

Während nun die Damen ihre Festznetzflatrate genießen, brodelt in mir das Unverständnis. Warum in aller Welt braucht man einen A/B Wandler für einen “ISDN” Anschluss von [ISP]?? Es existiert keine Telefonleitung mehr. Das was früher die Telefonleitung war, wurde dann um ein DSL Signal erweitert, und mittlerweile landet aus Kostengründen nurnoch ein DSL Signal in den Wohnzimmern, da die 64kBit, die eine ISDN Anleitung ausmachen mit der linken Pobacke erledigt werden. Also warum zur Hölle ein A/B Wandler??? Müssen den Telefonen 2 Leitungen vergegaukelt werden, damit sie sich Anklopfen lassen? Was is denn das bitte schön für ein Design? Was is, wenn ich zuvor keinen ISDN Anschluss vom rosa Panther hatte und noch eine jetzt nutzlose (dann ja doch nicht) Eumex oder sonstige Telefonanlage rumstehen habe? Oder wenn die schon bei ebay gesnipert wurde? Muss man das wissen?

Das sind natürlich Wasser auf die Mühlen der Freundin. Wenn noch nichtmal ich das weiß, da müssen die doch besser informieren. Naja… Die Leistung des ISPs ist das Signal. Dazu noch das Kästchen um es zu empfangen. Für 30€ im Monat kann man kein ausgefeiltes Migrationsprojekt mit Machbarkeitsstudie verlangen. Auch sehe ich nicht die ISPs in der Pflicht, kostenlose Support Hotlines anzubieten. Was hat der ISP mit der Infrastruktur beim Endanwender am Hut? Eigentlich nix. Die landläufige Meinung ist da allerdings ein wenig anders…