Trapezoidal distorsion when stitching scanned images

82 views
Skip to first unread message

Pierre Pierre

unread,
Aug 5, 2022, 1:42:13 PM8/5/22
to hugin and other free panoramic software
Hi all,

First, some background, I'm currently trying to digitize all my father's paintings and drawings; For artworks somewhat larger than my scanner I needed stitching, and have been using hugin for that purpose for a few months now.
Using a script heavily inspired by the one referenced in the "stiching scanned image" tutorial, or the script from Matthew Petroff (https://github.com/mpetroff/stitch-scanned-images) usually gives good results.
The main issue I'm often facing is that the output image has some kind of trapezoidal distortion, from mild to pronounced: usually the left end is taller than the right end.
I don't know why this happens, images overlap correctly and I can stitch the same images manually without too much effort (it's just a lot slower).
My current hypothesis is that output uses a rectilinear projection, but I'd need a projection that's both rectilinear and conformal. I there a way to request such optimization, or to postprocess control points mapping to convert it to a conformal mapping?
Thank you for your attention,
Pierre

Gunter Königsmann

unread,
Aug 5, 2022, 2:03:06 PM8/5/22
to Pierre Pierre, hugin and other free panoramic software
The head of my scanner isn't really horizontal bit slanted to one side by a few degrees. Maybe that is part of the problem for you, too?

Bruno Postle

unread,
Aug 5, 2022, 2:16:22 PM8/5/22
to hugin and other free panoramic software
Hi Pierre, I would first check that both the pitch and yaw of all your input photos is set to zero and that the output projection is set to rectilinear (not equirectangular).

Some scanners can produce quite strong 'shear' distortion, like a parallelogram, if the head is not exactly perpendicular to the tracks. Panotools/Hugin has g & t lens optimisation parameters that will correct this. You only need one or the other depending if your shear is horizontal or vertical.

I *think* g & t optimisation is hidden under a Hugin 'expert user' setting, I'm not at a computer at the moment so can't verify.

-- 
Bruno

Pierre Pierre

unread,
Aug 6, 2022, 5:15:07 AM8/6/22
to hugin and other free panoramic software
Thank you both for suggestions, I wasn't sure how to best measure shearing, so I scanned a try square multiple times, changing position and orientation, then used scalar product to calculate angle, and only found a few thousandth of degree discrepancies, which must be below measurement errors. If shearing exists, it's probably very small.

I added `--set x=0,y=0` to my `pto_var` call, it does seem to have the intended effect (limit transformations to translations and rotations) sometimes with visible output artefacts that are probably due to poor automatic selection of control points. I will see over time how often it'll require manual optimization, but detecting matching errors seems like an improvement.

--
Pierre

Pierre Pierre

unread,
Aug 11, 2022, 5:35:46 AM8/11/22
to hugin and other free panoramic software
Hi all, so here's a follow up to my investigations;
I figured out why I had bad matches: I had to revert the last change I made to my scripts, that removed TrZ optimization. Now I understand that the optimizer needs to be able to tweak TrZ to adjust TrZ, FoV and resolution together.

I'm back to good matches, but the trapezoidal distorsion is also back. So far it has never been severe anymore (maybe I've been lucky though), but it's noticeable enough that I prefer manual stitching when it happens :/
To rule out some slant in scanned images, I took an example of 4 scans that demonstrate the issue when stitched together, rotated all of the 180° (no rescan) and stitched them again that way;
And both time I get trapezoidal distorsion with left end taller than right end, so it doesn't follow images content, it seems there's some bias in the stitching process itself:


I created a tar with all resources needed to reproduce the problem, if somebody wants to investigate:


--
Pierre

Claudio Rocha

unread,
Aug 17, 2022, 7:05:36 PM8/17/22
to hugin and other free panoramic software
If you know that the original painting is indeed a parallelogram, and hopefully square, then you can create lines on the control points window to force Hugin to see Horizontal and Vertical lines. 
Reply all
Reply to author
Forward
0 new messages