Hugin++ : speedup of geometrical optimization for large panoramas

Hugin is a software for aligning and stitching several partially overlapping photos in order to get a bigger photo. Hugin uses Panarama tools that was originally developed by Helmut Dersch. Before stitching the photos, the software calculates the alignment (orientation and possibly position) and other parameters of the individual photos so that this is best consistent with the positions of all the control points in the images. This task is called geometrical optimization and is performed by PTOptimizer that is part of the libpano library.
When you have only a small or medium number of images and control points, PTOptimizer does the optimization in a fairly short time.

However if you have a large number of images (several hundrets or even thousand) and many control points, PTOptimizer typically needs much time for the optimization of the parameters. You may need to wait several days until PTOptimizer has finished.

I developed a version of PTOptimizer that dramatically decreases the processing time for large panoramas. This is possible by exploiting the sparseness of the mathematical optimization problem. The original PTOptimizer uses the well proven Levenberg Marquardt optimizer lmdif that is part of the minpack software (developed in in march 1980 by Burton S. Garbow, Kenneth E. Hillstrom, Jorge J. More, argonne national laboratory). This lmdif function performs internally a "dense" QR decomposition of the jacobian matrix. With dense I mean that no advantage is taken when only a small number of the matrix entries is nonzero like in the image alignment optimization problem. I have taken the code of lmdif and replaced the dense QR decompositions by sparse ones using the software package SuiteSparse (by Timothy A. Davis). I called my sparse Levenberg Marquardt optimizer lmdif_sparse.

For a large example panorama (with 1351 images and 273471 control points) my version of PTOptimizer speeds up the optimization by a factor of more than 200 compared to the original PTOptimizer. The smaller the panorama the smaller will be the speed gain factor, but I think it's worth using the sparse Levenberg Marquardt optimizer except you have only a few tens of images.

My version of PTOptimizer can be downloaded as part of the libpano library. It is a modified version of libpano13-2.9.20_rc3:

fastPTOptimizer at

I integrated the fastPTOptimizer into a fork of the Hugin software (mercurial version with latest update from 2021-05-01) that I call Hugin++.
Hugin++ can be downloaded here:

Hugin++ at

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.