Using Hugin (Panorama Tools GUI) to automatically stitch (merge) scanned images.

Written by Hasan Arous

Scanning documents into images is not a big deal, it is a matter of connecting the scanner, putting the document inside, clicking a button or two, and acquiring the image result… That easy.

But what if the physical size of the document you are trying to scan is larger than the size of the scanner? Well… that needs a bit of Orange Magic.

I don’t wanna read the story, take me to the step by step solution!

Website Management: Under the hood

Recently I was called by one of EtaBits clients, Mr. Sabhan Adam, to add scans of few art magazines to his website. I took the magazines and headed back to our office, to do the task.

In EtaBits, we offer website management solutions, which, in addition to developing the website, includes doing all the data entry and management of the website. It is a high level service, done by our web expert team, that aims at optimizing the data down to every bit. From formatting texts, to providing content with meta-data and optimizing images for faster load time while preserving quality…

So, as I started to scan the document, there was an “Oh no!”, the document was few centimeters wider than the scanner! I had the option to go somewhere where they offer document scanning services, they do have large scanners. But my decision was to keep that as plan B, with plan A to scan each page two times and then stitch them together using an image manipulation software (GIMP?).

Why not using a panorama software?

After getting the images, I though to my self “Hey, this is very similar to stitching individual panorama images!”. I started searching for softwares to do it, and found Hugin. I installed and launched it, tried a bit around, but did not find out how to do the task! I thought that maybe it is not very similar to panoramic images after all.

Left image scan Right image scan

I started GIMP, opened first image and expanded canvas, added the other one. Few minutes later I had them aligned, but I had two problems: one of the scanned images was slightly rotated, besides that one of them is darker than the other. I started fixing the situation, but thought again: Why not look further into Hugin? It should be programmed to take care of all the differences, ones I found about and other ones.

I searched again, and found a tutorial on stitching scanned images on hugin’s website! I had to update to a newer Hugin version, and the steps used are a bit different, probably due that I had an even newer version, or because the documentation did not cover the all auto path.

Automatically stitching two images, step by step!

Upgrading to a newer Hugin

sudo apt-add-repository ppa:hugin/hugin-builds
sudo apt-get update
sudo apt-get install hugin

Adding Images

  1. Open Hugin, from the “Assistant” tab, Click on “1. Load Images”.
  2. Select the images and continue.
  3. You’ll be asked on the HFoV, enter 10, an the scanner actually scans the document flat, not like the camera len when taking a shot. Adding Images

Auto, auto, and more auto

  1. Click on the “2. Align…” button, it will show an output window, wait until it finishes. This will align both images together.
  2. Go to the Move/Drag tab. Click on Center, Fit and then Straighten.
  3. From the Crop tab, click on Autocrop
  4. You can (optionally) expand the cropped area, from the bottom-right preview mode, while still on the Crop tab.

Panorama Editor

  1. Click on the “View” menu item, and choose “Ponorama editor”.
  2. In the “Photos” tab, select all images, then from the menu “Edit” choose “Optimize”.
  3. Go to “Stitcher” tab, click on Stitch! Panorama Editor Stitch!

Result

(Not edited after saving from Hugin, needs a little cropping) Final Stitched Image Impressive huh?

Notes

  • If it gives an error about enblend and enfuse not found, go to the “File” > “Preferences” menu, and go to the “Programs” tab, and enter full paths to the programs: enblend and enfuse settings

  • If it gives an error saying no input file, then the cropping area is small, increase it in the Crop tab.

Should you need any help, feel free to ask