Developing a batch file for mosaic stitching with the highest possible quality

93 views
Skip to first unread message

Bernd D

unread,
Jul 20, 2016, 4:54:22 AM7/20/16
to hugin and other free panoramic software

Hello,

I would like to use panotools to stitch a photo-mosaic in batch mode. The information that I use is from here:

(and so on)

First I create a batch file that automated the process for a 5x5 mosaic:

@ECHO OFF
@SET IMAGES=T??.tif
@SET PREFIX=Test
@SET HUGIN=c:\Program Files (x86)\Hugin\bin
@"%HUGIN%\pto_gen.exe" --projection=0 --fov=5 -o project.pto %IMAGES%
@"%HUGIN%\pto_lensstack.exe" -o project1.pto --new-lens i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14,i15,i16,i17,i18,i19,i20,i21,i22,i23,i24 project.pto
@"%HUGIN%\cpfind.exe" --multirow --fullscale -o project2.pto project1.pto
@"%HUGIN%\cpclean.exe" -o project3.pto project2.pto
@"%HUGIN%\pto_var.exe" -o setoptim.pto --opt TrX,TrY project3.pto
@"%HUGIN%\autooptimiser.exe" -n -o autoptim.pto setoptim.pto
@"%HUGIN%\pano_modify.exe" --projection=0 --fov=AUTO --canvas=AUTO --crop=AUTO -o autoptim2.pto autoptim.pto
@"%HUGIN%\hugin_executor.exe" --stitching --prefix=%Prefix% autoptim2.pto
 

Then I have written a simple tool that makes test images:

  • generates a 4000x4000 image with random pixels
  • draw cross marker every 20 pixel
  • draw  a one pixel wide frame
  • Save the resulting image
  • Cut 5x5 tiles, with 1000x1000 Pixel (250 pixel overlapped) and save this to image T00.tif..T24.tif.

The random pixels cause that each pixel is a very good comparison candidate for finding Control Points. The marker and the frame facilitate the interpretation of the stitching result.

I expected that panotools can stitch these tiles together only with errors in sub pixel dimension. But the error is significantly larger. After much trial and error I found a solution for this particular case. Based on the test images, I found out that pano_modify.exe caused the error. This program calculates the p line in autoptim2.pto:

p f0 w6857 h6857 v129  E0 R0 S2928,6857,2928,6857 n"TIFF_m c:LZW r:CROP"

I can correct this manually:

  • Open autoptim2.pto in hugin

  • On Sticher Tab, Change Field of View, Horizontal and Vertical  from 129 to 130.

  • Press the “Calculate optimal size” Button.

  • Press the “Fit crop to images” Button

The result is:

p f0 w7014 h7014 v130  E0 R0 S3007,7007,3007,7007 n"TIFF_m c:LZW r:CROP"

 With these settings, hugin produces a sub pixel accurate image. Of course, that is not really a useful solution for me, because my batch file must provide a correct output image for any set of input images.

Now my questions:

  1. How can I automatically calculate the correct Field of View? Or even better: Is there a way, to bypass the unnecessary Field of View parameter, so that the intermediate images are not scaled.?

  2. How can I avoid that w and h are unnecessarily large? Better as

     p f0 w7014 h7014 v130  E0 R0 S3007,7007,3007,7007 n"TIFF_m c:LZW r:CROP"
    would be
    p f0 w4000 h4000 v130  E0 R0 S0,0,3999,3999 n"TIFF_m c:LZW r:CROP"
    Expressed differently: How can I shift the projection to a minimum canvas? Or is the canvas size only a virtual size which is not physically created?

  3. Why does the command line parameter " --dry-run "for hugin_executor not work? See  http://wiki.panotools.org/Hugin_executor. Are the individual commands documented somewhere else?

If someone wants to try the test, here is my test image generator tool:

http://www.file-upload.net/download-11778244/I2T.zip.html

Viruscheck: https://www.virustotal.com/

SHA256: ca729b9ba382d63a831a416fed2389647433476f1424b7616591a8abc2297e1d
File name: I2T.exe
  

To create the test images: Press „Random“ Button, Press „Draw Marker“ Button, Enter the target directory in the box to the left of the "Save" button. Press the „Save“ Button.

Thanks in advance

Bernd Derer

Abrimaal

unread,
Jul 21, 2016, 8:57:04 AM7/21/16
to hugin and other free panoramic software


On Wednesday, July 20, 2016 at 10:54:22 AM UTC+2, Bernd D wrote:

Hello,

I would like to use panotools to stitch a photo-mosaic in batch mode. The information that I use is from here:

(...)

 Hugin is generally for photos taken with various lenses. I was trying to stitch a map according to the tutorial above, but the image was always distorted, there are too many parameters to input.
My suggestion to the developers is: Flat document stitching in the rectilinear projection with only these checkboxes at start
[  ] exposure correction
[  ] horizontal / vertical line detection
[  ] high contrast priority (for such documents as maps, technical drawings, scanned text) to restrict searching for control points

All the other steps are skipped. Optionally to allow enblend / enfuse when the images do not match exactly.

Reply all
Reply to author
Forward
0 new messages