Alignment of multi-row images

418 views
Skip to first unread message

Mike Cowlishaw

unread,
Nov 2, 2015, 7:07:42 AM11/2/15
to hugin and other free panoramic software
I've been using Hugin for some time and have always got excellent results with panoramas from up to 4 x 6 images.  However I recently tried a much larger set (6 x 12) and the align step failed badly with messages about many unconnected images.   If I take a subset (e.g., the first 12 images) alignment works as normal.

I wonder whether the order of the images makes a difference (these are top-to-bottom, a column at a time, whereas before I've always done left-to-right, a row at a time)?   Or is there a way I can 'tell' Hugin how the images are arranged?

If not, any suggestions?  This is a fresh installation of 2015.0.0 with no settings changed.

Thanks -- Mike

Bruno Postle

unread,
Nov 2, 2015, 8:59:19 AM11/2/15
to hugi...@googlegroups.com


On 2 November 2015 12:07:06 GMT+00:00, Mike Cowlishaw wrote:
>
>I wonder whether the order of the images makes a difference (these are
>top-to-bottom, a column at a time, whereas before I've always done
>left-to-right, a row at a time)?

Hugin does assume rows by default (you can change this in the preferences window). It should be able to cope with up-down patterns just as well as left-right, and zig-zag arrangements should work as well.

Unless there are gaps or featureless areas, like blue sky, it's difficult to say what the problem is, can you upload a sample somewhere?

--
Bruno

Mike Cowlishaw

unread,
Nov 3, 2015, 10:09:07 AM11/3/15
to hugin and other free panoramic software
Bruno, thanks for the quick reply!   Two separate questions here, I now think.



>I wonder whether the order of the images makes a difference (these are
>top-to-bottom, a column at a time, whereas before I've always done
>left-to-right, a row at a time)?

Hugin does assume rows by default (you can change this in the preferences window).

I looked before and just had another look -- where in Preferences does one change this?  I would have thought Hugin would need this in other to make a sensible initial display of the loaded images (at present it shows a strange patchwork).  Also, perhaps, if Hugin was told how the images were arranged it could speed up the alignment process.

 
It should be able to cope with up-down patterns just as well as left-right, and zig-zag arrangements should work as well.

Unless there are gaps or featureless areas, like blue sky, it's difficult to say what the problem is, can you upload a sample somewhere?  

Ah, thanks, that has prompted me to do some more experiments.  I can process more than half the images without problems, but there are indeed 4 (of the 72) that are featureless white sky (necessarily/deliberately overexposed), and the 'unconnected groups' messages appear when they are part of the selected source images.

I'm not sure what to do in this case: I am invited to add control points, but there can be none?.

I've uploaded the rightmost 4 columns (24 JPGs) as a sample that 'fails' (and also shows the less-than-ideal initial display of images), at http://speleotrove.com/testpan.zip -- any suggestions on how to proceed would be much appreciated!

Mike



 

T. Modes

unread,
Nov 3, 2015, 2:40:50 PM11/3/15
to hugin and other free panoramic software

Am Dienstag, 3. November 2015 16:09:07 UTC+1 schrieb Mike Cowlishaw:
It should be able to cope with up-down patterns just as well as left-right, and zig-zag arrangements should work as well.

Unless there are gaps or featureless areas, like blue sky, it's difficult to say what the problem is, can you upload a sample somewhere?  

Ah, thanks, that has prompted me to do some more experiments.  I can process more than half the images without problems, but there are indeed 4 (of the 72) that are featureless white sky (necessarily/deliberately overexposed), and the 'unconnected groups' messages appear when they are part of the selected source images.

I'm not sure what to do in this case: I am invited to add control points, but there can be none?.

With the featureless images it becomes a little bit more complicated, but not impossible.
Have a look at the geocpset tool http://wiki.panotools.org/Geocpset
 

I've uploaded the rightmost 4 columns (24 JPGs) as a sample that 'fails' (and also shows the less-than-ideal initial display of images), at http://speleotrove.com/testpan.zip -- any suggestions on how to proceed would be much appreciated!

For your test set the sequence would be something like:
pto_gen --output=project.pto *.pto
pto_var "--set=y=floor(i/6)*13,p=27-(i%6)*9" --output=project.pto project.pto
cpfind --output=project.pto --prealigned project.pto
geocpset --output=project.pto project.pto

(Quoting is for Windows.)

For your full project you will need to adopt probably the parameters for pto_var.

Mike Cowlishaw

unread,
Nov 4, 2015, 10:15:22 AM11/4/15
to hugi...@googlegroups.com
OK, many thanks .. working through the documentation on those and building a script; will report in due course.   The documentation for pto_var is especially skimpy.   Are the constants you suggest (13, 27, 9) in degrees?  The functions seem to work in radians.   Also I assume the origin for the positions is bottom-left.

Mike

--
A list of frequently asked questions is available at: http://wiki.panotools.org/Hugin_FAQ
---
You received this message because you are subscribed to a topic in the Google Groups "hugin and other free panoramic software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hugin-ptx/ImcaDTH7KMY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hugin-ptx+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hugin-ptx/032c6202-bf80-430a-b4b6-21d3c28c73fb%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

T. Modes

unread,
Nov 4, 2015, 11:29:08 AM11/4/15
to hugin and other free panoramic software


Am Mittwoch, 4. November 2015 16:15:22 UTC+1 schrieb Mike Cowlishaw:
OK, many thanks .. working through the documentation on those and building a script; will report in due course.  

That would be nice. There is no much feedback for this workflow/tools.
 
The documentation for pto_var is especially skimpy.  

I know. It requires some knowledge of the pto file format. Until now nobody helped with this.
The easiest way is to have a look on the photos tab for an existing project. There you will find all variables (and it short character)
 
Are the constants you suggest (13, 27, 9) in degrees?  The functions seem to work in radians.  

Yes, yaw, pitch and roll are in degree.
Your example images have a horizontal field of view of about 22 deg. With an estimated overlap of 40 % you will get an delta yaw of 13 deg.
For pitch this is similar: The vertical field of view is about 16 deg. So you get an delta pitch of 9 deg. The 27 is to get the middle image of each row near to the horizon. This last one would not be strictly necessary.

An easier way is to use a subset (maybe all rows, but only 2 columns), run the assistant and look on the photo tab and deduce the necessary angle/formulas.
(Or load a subset of images and move them with the drag tool to raw positions and then look on the photos tab.)

Also I assume the origin for the positions is bottom-left.

No. It is a spherical coordinate system with 0,0 in the middle.
cpfind is using the full sphere for calculation. So the origin is not so important, because the 0-360/-90-+90 deg boundary is taken into account.

Message has been deleted

Mike Cowlishaw

unread,
Nov 6, 2015, 10:24:33 AM11/6/15
to hugin and other free panoramic software
[Last post had wrong command copy .. retry...]


Many thanks for that.  Making progress :-).   My script generates the correct commands, I think:

  pto_gen -o project.pto p*.jpg
  pto_var "--set=y=(floor(i/6)*13.5719189)-20.3578783,p=25.5922968-(i%6)*10.2369187" --output=project.pto project.pto
  cpfind --output=project.pto --prealigned project.pto
  geocpset --output=project.pto project.pto


but the cpfind command gives the following errors (varies according to the run):
 
  
  i0 : Analyzing image...
  i1 : Analyzing image...
  i2 : Analyzing image...
  i3 : Analyzing image...
  i4 : Analyzing image...
  i5 : Analyzing image...
  i6 : Analyzing image...
  i7 : Analyzing image...
  An error happened while loading image : caught exception: bad allocation
  i8 : Analyzing image...
  An error happened while loading image : caught exception: bad allocation
  i9 : Analyzing image...
  An error happened while loading image : caught exception: bad allocation
  i10 : Analyzing image...
  An error happened while loading image : caught exception: bad allocation

  [more of the same deleted]

The geocpset command seems to work, but when I then open the .pto file in Hugin there are severe stitching errors -- 

presumably only the geometrical control points are being used. 
 
This is on Windows 64 with 16GB of RAM (free RAM typically 10-12GB).  Any ideas?

Mike

Terry Duell

unread,
Nov 6, 2015, 5:19:46 PM11/6/15
to hugi...@googlegroups.com
Hello Mike,

On Sat, 07 Nov 2015 02:24:32 +1100, Mike Cowlishaw <mfc.s...@gmail.com>
wrote:

> [Last post had wrong command copy .. retry...]
>
>
> Many thanks for that. Making progress :-). My script generates the
> correct commands, I think:
>
> pto_gen -o project.pto p*.jpg
> pto_var
> "--set=y=(floor(i/6)*13.5719189)-20.3578783,p=25.5922968-(i%6)*10.2369187"
> --output=project.pto project.pto
> cpfind --output=project.pto --prealigned project.pto
> geocpset --output=project.pto project.pto
>
>
> but the cpfind command gives the following errors (varies according to
> the run):

One thing I do when first writing scripts like this is to have each step
generate a new .pto file, then when it's done you can load each one in
turn into Hugin and see if it has done what you want.

Cheers,
--
Regards,
Terry Duell

Mike Cowlishaw

unread,
Nov 7, 2015, 3:58:36 AM11/7/15
to hugi...@googlegroups.com
Hi, yes, the commands look good -- it is the errors that seem to be causing the problems.  Sometimes (with the same set of images) there are only one or two error messages, and the result then is OK.

The errors are of the form:

  i7 : Analyzing image...
  An error happened while loading image : caught exception: bad allocation

Mike

--
A list of frequently asked questions is available at: http://wiki.panotools.org/Hugin_FAQ
---You received this message because you are subscribed to a topic in the Google Groups "hugin and other free panoramic software" group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/hugin-ptx/ImcaDTH7KMY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hugin-ptx+...@googlegroups.com.

T. Modes

unread,
Nov 7, 2015, 4:17:20 AM11/7/15
to hugin and other free panoramic software


Am Samstag, 7. November 2015 09:58:36 UTC+1 schrieb Mike Cowlishaw:
The errors are of the form:

  i7 : Analyzing image...
  An error happened while loading image : caught exception: bad allocation

You are using the 64 bit version? (If you are using the 32 bit version, try the 64 bit version.)

You could try to limit the number of threads with
SET OMP_NUM_THREADS=4
(before running cpfind)
to reduce the memory usage.
(I have seen this error only when there is memory shortage in case of many threads.)

Mike Cowlishaw

unread,
Nov 7, 2015, 5:42:27 AM11/7/15
to hugin and other free panoramic software

The errors are of the form:

  i7 : Analyzing image...
  An error happened while loading image : caught exception: bad allocation

You are using the 64 bit version? (If you are using the 32 bit version, try the 64 bit version.)

I believe so -- I only have the 64-bit installer .exe, but About Hugin doesn't say either way.
 

You could try to limit the number of threads with
SET OMP_NUM_THREADS=4
(before running cpfind)
to reduce the memory usage.
(I have seen this error only when there is memory shortage in case of many threads.)

That didn't help.   The odd thing is that these errors do not occur when cpfind is run from the Hugin assistant ('Align').



 

Mike Cowlishaw

unread,
Nov 7, 2015, 6:01:00 AM11/7/15
to hugin and other free panoramic software
Just tried running my script for just the pto_gen and pto_var commands, then opening the .pto with Hugin, running Align, saving, running the geocpset command, opening the .pto again, and stitching.

This runs without errors, but the result is truly awful -- even 'easy' bits such as the car is not stitched correctly.

So I am somewhat discouraged -- wondering if anyone else can get this to work.

Mike

T. Modes

unread,
Nov 7, 2015, 6:15:44 AM11/7/15
to hugin and other free panoramic software


Am Samstag, 7. November 2015 12:01:00 UTC+1 schrieb Mike Cowlishaw:
Just tried running my script for just the pto_gen and pto_var commands, then opening the .pto with Hugin, running Align, saving, running the geocpset command, opening the .pto again, and stitching.

This runs without errors, but the result is truly awful -- even 'easy' bits such as the car is not stitched correctly.

After geocpset and opening the pto file again you need to optimize the position and photometric parameters to get the final result. (Do it manually on the photos tab or press align again)
Otherwise only rough position from pto_var are used.

Mike Cowlishaw

unread,
Nov 7, 2015, 7:25:48 AM11/7/15
to hugin and other free panoramic software


After geocpset and opening the pto file again you need to optimize the position and photometric parameters to get the final result. (Do it manually on the photos tab or press align again)
Otherwise only rough position from pto_var are used.


Ah!!  That works perfectly!   Very many thanks.   Presumably I can add that step to the script by calling cpfind  again (with --prealigned?) ?

I've solved the allocation error, too -- the 32-bit hugin/bin directory was ahead of the 64-bit hugin/bin in my PATH :-(  Long story as to how that happened....  

Mike Cowlishaw

unread,
Nov 7, 2015, 7:45:39 AM11/7/15
to hugin and other free panoramic software

Ah!!  That works perfectly!   Very many thanks.   Presumably I can add that step to the script by calling cpfind  again (with --prealigned?) ?

Ignore that last question .. I see that won't work.

Here, as promised, is the script I put together.  Plenty of room for improvement...

/* --------------------------------------------------------------- */
/* huginpan.rex --- run Hugin with layout hints                    */
/* --------------------------------------------------------------- */
/*                                                                 */
/* Call as:                                                        */
/*                                                                 */
/*   huginpan pattern lens columns rows order                      */
/*                                                                 */
/* where:                                                          */
/*                                                                 */
/*   pattern -- source files pattern (e.g., P*.jpg)                */
/*   lens    -- lens length (mm, 35mm equivalent)                  */
/*   columns -- number of images in X dimension                    */
/*   rows    -- ditto in Y                                         */
/*   order   -- mapping of image sequence to rectangle             */
/*                                                                 */
/* pattern, lens, and columns are required                         */
/* rows default=1, order default=0                                 */
/*                                                                 */
/* order is:                                                       */
/*                                                                 */
/*   0 -- rows, left->right, top->bottom (start top-left)          */
/*   1 -- columns, top->bottom, left->right (start top-left)       */
/*                                                                 */
/* Before using this, it is suggested that you copy the source     */
/* files to their own subdirectory, then run this command with     */
/* that as the current directory.                                  */
/*                                                                 */
/* Return codes from pto_ commands are not documented, so ignored. */
/* --------------------------------------------------------------- */
-- 2015.11.04 mfc initial vesrion
-- 2015.11.06 add lens length as parameter

-- ensure path to Hugin 64-bit programs [needed for cpfind]
'SET PATH=c:\Program Files\Hugin\bin;%PATH%'

parse arg pattern lens columns rows order .
if columns='' then do
  say 'Pattern, lens, and columns must be specified'
  exit -1
  end
if rows='' then rows=1
if order='' then order=0

-- set up constants (could be parameters or options, later)
-- short-edge equivanet sensor size is assumed to be as 4:3 35mm (27mm)
aspect=4/3          -- sensor horizontal:vertical ratio
portrait=0          -- 1 if camera in portrait (vertical) format
overlap=0.4         -- overlap between images as a fraction

-- calculate total degrees vertical and horizontal
h=2*arctan((27*aspect) / (2*lens)) -- sensor horizontal degrees
v=2*arctan(27 / (2*lens))          -- ditto vertical
if portrait then do                -- swap if portrait
  temp=h
  h=v
  v=temp
  end
-- now have degrees for h and v for one image
say 'Image degrees:' h 'x' v

totalh=h*(columns - overlap*(columns-1))
totalv=v*(rows    - overlap*(rows-1))
say 'Total degrees:' totalh 'x' totalv

-- set up the pitch and yaw formulae
-- absolute origin non-critical
eh=h*(1-overlap)                   -- effective horizontal degrees
ev=v*(1-overlap)                   -- effective vertical degrees
offseth=totalh/2 - h/2             -- offset for 0,0 image
offsetv=totalv/2 - v/2             -- ..

select
  when order=0 then do             -- TL, by row, left->right
    yaw='(i%'columns')*'eh'-'offseth
    pitch=offsetv'-(floor(i/'columns')*'ev')'
    end
  when order=1 then do             -- TL, by column, top->bottom
    yaw='(floor(i/'rows')*'eh')-'offseth
    pitch=offsetv'-(i%'rows')*'ev
    end
  otherwise do
    say 'Bad order specified:' order
    exit -1
    end
  end
say 'yaw='yaw 'pitch='pitch


----- process the images using Hugin commands -----

profile='project.pto'         -- project filename
call sysfiledelete profile

-- create the Hugin project file
'pto_gen -o' profile pattern

-- update/set rough geometricals
'pto_var "--set=y='yaw',p='pitch'" --output='profile profile

-- find control points
'cpfind --output='profile '--prealigned' profile

-- add missing control points using geometry
'geocpset --output='profile profile

-- done
say
say 'Starting Hugin.  Open' profile', Align, and Generate Panorama'
'start "Hugin" Hugin'

Paul Womack

unread,
Nov 7, 2015, 12:29:10 PM11/7/15
to hugi...@googlegroups.com
What (on earth) is your Hugin installed on, such that Rex
is your scripting language of choice?!

 BugBear

Mike Cowlishaw

unread,
Nov 7, 2015, 1:01:15 PM11/7/15
to hugin and other free panoramic software


On Saturday, 7 November 2015 17:29:10 UTC, bugbear wrote:
What (on earth) is your Hugin installed on, such that Rex
is your scripting language of choice?!

Windows.  But it is also my scripting language of choice on Linux.  After all, I created Rex[x] :-).  

Mike 

T. Modes

unread,
Nov 7, 2015, 1:37:19 PM11/7/15
to hugin and other free panoramic software


Am Samstag, 7. November 2015 13:45:39 UTC+1 schrieb Mike Cowlishaw:
<snip>
 
-- add missing control points using geometry
'geocpset --output='profile profile

-- done
say
say 'Starting Hugin.  Open' profile', Align,

this can also be achieved from the command line: hugin_executor --assistant ..
 
and Generate Panorama'

same here: hugin_executor --stitching …
 

 

Mike Cowlishaw

unread,
Nov 7, 2015, 1:44:47 PM11/7/15
to hugin and other free panoramic software
OK .. many thanks; will try those soon (not tomorrow).   Is there an overview of hugin commands, like those, somewhere?   I googled and browsed for some time and did not come across 'hugin_executor',as far as I recall.
 

Gerald Brosseau

unread,
Nov 7, 2015, 1:51:56 PM11/7/15
to hugi...@googlegroups.com
Is it the same Rex as the one under OS/2?
--
A list of frequently asked questions is available at: http://wiki.panotools.org/Hugin_FAQ
---
You received this message because you are subscribed to the Google Groups "hugin and other free panoramic software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hugin-ptx+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hugin-ptx/06f0ea44-3b6f-4816-8546-35578767ca2c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

-- 
Gérald Brosseau
La Photo Du Jour 
(www.gb-photodujour.com)
Sur internet depuis 1998

T. Modes

unread,
Nov 7, 2015, 1:54:41 PM11/7/15
to hugin and other free panoramic software


Am Samstag, 7. November 2015 19:44:47 UTC+1 schrieb Mike Cowlishaw:
OK .. many thanks; will try those soon (not tomorrow).   Is there an overview of hugin commands, like those, somewhere?   I googled and browsed for some time and did not come across 'hugin_executor',as far as I recall.

see http://wiki.panotools.org/Panorama_scripting_in_a_nutshell
This file is also contained in Hugins help file.

Mike Cowlishaw

unread,
Nov 7, 2015, 3:19:55 PM11/7/15
to hugin and other free panoramic software

see http://wiki.panotools.org/Panorama_scripting_in_a_nutshell
This file is also contained in Hugins help file.

Perfect -- thanks.  

As mentioned, I didn't find anything like that when searching; maybe worth 'highlighting' in some way? 

Mike Cowlishaw

unread,
Nov 7, 2015, 3:29:05 PM11/7/15
to hugin and other free panoramic software


On Saturday, 7 November 2015 18:51:56 UTC, Gerald wrote:
Is it the same Rex as the one under OS/2?

There are several implementations (all support the ANSI Standard Rexx, I think).  The open object Rexx (ooRexx) that is the current open source/free version is, indeed, based on the OS/2 Object Rexx ... but much enhanced from that. 

Perhaps more to the point of this thread is that Rexx was designed to process strings in order to create "commands", which is exactly what is required for the commands that Hugin/panotools expect.  

Thomas Käfer

unread,
Mar 7, 2021, 3:54:44 AM3/7/21
to hugin and other free panoramic software
Thanks for publishing this. I've used what I've learned from your script to make this much simpler much more rigid script for a panorama poor in features that I'm currently trying to stich togetether:

#!/bin/bash

pto_gen -o scripting_step1_images.pto IMG_*.JPG

# https://wiki.panotools.org/Panorama_scripting_in_a_nutshell

# https://groups.google.com/g/hugin-ptx/c/ImcaDTH7KMY/m/GcHI-wNnFAAJ
# https://wiki.panotools.org/Pto_var
# simplified layout asuming 360° panorama
# rows are not needed in calculation, it's assumed that rows = number of pictures / columns
columns=8
degrees_below_horizon=55 # how far below the horizon does the panorama start?
field_of_view_horizontal=$((360/$columns)) # not the real field_of_view, subtract half of the overlap..
echo "field_of_view_horizontal = $field_of_view_horizontal"
field_of_view_vertical=$(($field_of_view_horizontal/4*3))
pto_var --set="y=(i%$columns)*$field_of_view_horizontal,p=floor(i/$columns)*$field_of_view_vertical-$degrees_below_horizon,r=0" --output=scripting_step2_align_rows_and_columns.pto scripting_step1_images.pto

pto_mask --process=CLIP --mask=mask.msk@0 --mask=mask.msk@1 --mask=mask.msk@2 --mask=mask.msk@3 --mask=mask.msk@4 --mask=mask.msk@5 --mask=mask.msk@6 --mask=mask.msk@7 --output=scripting_step3_masks.pto scripting_step2_align_rows_and_columns.pto

# https://wiki.panotools.org/Cpfind
# --multirow --sieve2width=10 --sieve2height=10 --sieve2size=20 --minmatches=1
cpfind --verbose --prealigned --fullscale --cache --output=scripting_step4_prealigned_cpfind.pto scripting_step3_masks.pto

linefind --output=scripting_step5_vertical-lines.pto scripting_step4_prealigned_cpfind.pto

# https://wiki.panotools.org/Geocpset
geocpset --each-overlap --output=scripting_step6_geocpset.pto scripting_step5_vertical-lines.pto

autooptimiser -a -m --output=scripting_step7_autoptimized.pto scripting_step6_geocpset.pto

hugin scripting_step7_autoptimized.pto


Thank you :)

Mike Cowlishaw

unread,
Mar 7, 2021, 6:08:42 AM3/7/21
to hugi...@googlegroups.com
Thanks for the thanks :-).  Glad it was useful!

--
A list of frequently asked questions is available at: http://wiki.panotools.org/Hugin_FAQ
---
You received this message because you are subscribed to a topic in the Google Groups "hugin and other free panoramic software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hugin-ptx/ImcaDTH7KMY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hugin-ptx+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages