Focal length and FOV badly defined in Hugin?

170 views
Skip to first unread message

Torsten Bronger

unread,
Mar 26, 2014, 2:39:22 AM3/26/14
to hugi...@googlegroups.com
Hallöchen!

If I understand the Hugin projection model correctly, the distance
of a pixel from the image centre r (in real-world coordinates),
depending of the angle of the incoming light ray with respect to the
optical axis, is

r(alpha) = f * (a*r^3 + b*r^2 +c*r + 1 - a - b - c) * tan(alpha)

where "tan(alpha)" is for rectilinear lenses, and being replaced by
other terms of other types of lenses.

However then, the focal length f is wrongly defined. In the
paraxial approximation, where r and alpha --> 0, you get

r(alpha) = f * (1 - a - b - c) * alpha

but it should be

r(alpha) = f * alpha.

So, Hugin moves some of the distortion into the focal length,
getting the focal length wrong by a factor of (1 - a - b - c). I
suspect that the FOV is equally affected. That said, the projection
formula as a whole does a correct mapping.

Is this historical burden from the PT project that we have to live
with, or is this focal length thing "far enough" form the core that
it is worth a bug report? I mean, old FOV values would become
incompatible if this was fixed. On the other hand, one could
maybe only fix the displayed "focal length" in the GUI, as I think
this is not written to the files anyway.

I ask this because I care for the Lensfun project at the moment, and
it inherits all the formulae from Hugin. With all their quirks.
;-)

Tschö,
Torsten.

--
Torsten Bronger Jabber ID: torsten...@jabber.rwth-aachen.de
or http://bronger-jmp.appspot.com

Torsten Bronger

unread,
Mar 26, 2014, 4:29:27 PM3/26/14
to hugi...@googlegroups.com
Hallöchen!

Torsten Bronger writes:

> If I understand the Hugin projection model correctly, the distance
> of a pixel from the image centre r (in real-world coordinates),
> depending of the angle of the incoming light ray with respect to
> the optical axis, is
>
> r(alpha) = f * (a*r^3 + b*r^2 +c*r + 1 - a - b - c) * tan(alpha)

Sorry, was is wrong. It should read

r(α) = f · (a rᵤ³ + b rᵤ² + c rᵤ + 1 - a - b - c), with rᵤ = tan(α).

FabKzo

unread,
Apr 2, 2014, 10:52:49 AM4/2/14
to hugi...@googlegroups.com

Hi,

 I'm not a dev, but does this mean that having a 29.42 mm instead of 28mm ,for example, would be the result ? So all calculus to find Hfov from there should be bad?

Bruno Postle

unread,
Apr 2, 2014, 3:29:21 PM4/2/14
to hugi...@googlegroups.com


On 26 Mar 2014 06:41, "Torsten Bronger" wrote:
>
> If I understand the Hugin projection model correctly, the distance
> of a pixel from the image centre r (in real-world coordinates),
> depending of the angle of the incoming light ray with respect to the
> optical axis, is
>
> r(alpha) = f * (a*r^3 + b*r^2 +c*r + 1 - a - b - c) * tan(alpha)
>
> where "tan(alpha)" is for rectilinear lenses, and being replaced by
> other terms of other types of lenses.
>
> However then, the focal length f is wrongly defined.  In the
> paraxial approximation, where r and alpha --> 0, you get

It is a long time since I looked at this, and I haven't checked your maths, but this is how I remember it:

The field of view and any calculation of focal length is correct — when a, b & c are zero.

The a, b & c parameters shift pixels radially, so pixels at the sides of a landscape format photo will move. For example a 50° landscape photo will occupy 50° of the output panorama; but if you change a, b or c then the same photo might occupy 52° (or some other value).

The a, b & c parameters are fixed to the narrowest width, so the side pixels of a portrait photo _don't_ move.

This does seem odd, but it is difficult to think of a lens model where there is a simple relationship between horizontal and vertical angle of view for anything other than a simple pinhole camera. The panotools model has an advantage that you can use the same distortion parameters for portrait and landscape images taken with the same setup.

--
Bruno

Torsten Bronger

unread,
Apr 3, 2014, 6:55:03 AM4/3/14
to hugi...@googlegroups.com
Hallöchen!

Bruno Postle writes:

> [...]
>
> The field of view and any calculation of focal length is correct —
> when a, b & c are zero.

Okay, clear.

> The a, b & c parameters shift pixels radially, so pixels at the
> sides of a landscape format photo will move. For example a 50°
> landscape photo will occupy 50° of the output panorama; but if you
> change a, b or c then the same photo might occupy 52° (or some
> other value).

(*)
... assumed Hugin's FOV value is fixed, right? In other words:
Hugin's FOV is a representation of the focal length of the lens used
in the undistorted lens projection formula, rather than the actual
angle-of-view of the image. (I'm not criticising this, I just need
to know.)

> The a, b & c parameters are fixed to the narrowest width, so the
> side pixels of a portrait photo _don't_ move.
>
> This does seem odd, but it is difficult to think of a lens model
> where there is a simple relationship between horizontal and
> vertical angle of view for anything other than a simple pinhole
> camera.

For an equidistant lens, it is simple. But for a pinhole camera,
you still have the nasty tan() in the formula, don't you?

> The panotools model has an advantage that you can use the same
> distortion parameters for portrait and landscape images taken with
> the same setup.

This would also work if r_d = r_u * (a*r_u^3 + b*r_u^2 + c*r_u + 1),
i.e. without the "-a-b-c", because by definition r_u is scaled to
the shorter dimension, which is the same for portrait and landscape.
Plus, this has the advantage that Hugin's value for the "focal
length" would then represent the physically correct focal length of
the lens.

I still don't see the advantage of the fixed point on the long image
edge. In Lensfun, it often makes autoscaling (to get rid of black
corners) unnecessary. But even this fails often enough.

That said, I'm aware this all this cannot be changed anymore. So
actually, I only need to know (*).

Torsten Bronger

unread,
Apr 3, 2014, 8:33:00 AM4/3/14
to hugi...@googlegroups.com
Hallöchen!

FabKzo writes:

> I'm not a dev, but does this mean that having a 29.42 mm instead
> of 28mm, for example, would be the result? So all calculus to find
> Hfov from there should be bad?

AFAIKS, everything is fine. Hugin's calculations are precise. The
only issue is that Hugin defines a focal length different from the
one that an optics textbook would define, that's all.

Bruno Postle

unread,
Apr 7, 2014, 5:30:04 PM4/7/14
to hugi...@googlegroups.com
On 3 April 2014 11:55, Torsten Bronger <bro...@physik.rwth-aachen.de> wrote:
>
>> The a, b & c parameters shift pixels radially, so pixels at the
>> sides of a landscape format photo will move. For example a 50°
>> landscape photo will occupy 50° of the output panorama; but if you
>> change a, b or c then the same photo might occupy 52° (or some
>> other value).

> ... assumed Hugin's FOV value is fixed, right? In other words:
> Hugin's FOV is a representation of the focal length of the lens used
> in the undistorted lens projection formula, rather than the actual
> angle-of-view of the image. (I'm not criticising this, I just need
> to know.)

Yes, Hugin's angle of view relates to a 'perfect' photo without barrel
distortion. If you measure the angle of a 'real' photo you might get a
different number.

>> This does seem odd, but it is difficult to think of a lens model
>> where there is a simple relationship between horizontal and
>> vertical angle of view for anything other than a simple pinhole
>> camera.
>
> For an equidistant lens, it is simple. But for a pinhole camera,
> you still have the nasty tan() in the formula, don't you?

The tan() is easy enough, the complication happens when you add
radial/barrel distortion (with fisheye and normal lenses).

--
Bruno

Erik Krause

unread,
Apr 7, 2014, 7:12:23 PM4/7/14
to hugi...@googlegroups.com
Am 03.04.2014 14:33, schrieb Torsten Bronger:

> AFAIKS, everything is fine. Hugin's calculations are precise. The
> only issue is that Hugin defines a focal length different from the
> one that an optics textbook would define, that's all.

Optics textbook definitions are simplified, they deal with ideal lenses.
Real lenses suffer from distortions which effectively result in a
different magnification throughout the image (modeled by the hugin /
panotools distortion formula). F.e. higher magnification in the image
center means barrel distortion. Focal length and magnification are
simply related, so there is no precise single focal length for most real
life lenses.

This is most significant for fisheye lenses. The popular Samyang 8mm
lens f.e. is even marketed as different focal length. You only can give
an approximate value after you estimated the mapping formula:
http://michel.thoby.free.fr/SAMYANG/Early%20test%20report.html

--
Erik Krause
http://www.erik-krause.de

Torsten Bronger

unread,
Apr 8, 2014, 2:36:18 AM4/8/14
to hugi...@googlegroups.com
Hallöchen!

Erik Krause writes:

> Am 03.04.2014 14:33, schrieb Torsten Bronger:
>
>> AFAIKS, everything is fine. Hugin's calculations are precise.
>> The only issue is that Hugin defines a focal length different
>> from the one that an optics textbook would define, that's all.
>
> Optics textbook definitions are simplified, they deal with ideal
> lenses. Real lenses suffer from distortions which effectively
> result in a different magnification throughout the image (modeled
> by the hugin / panotools distortion formula). F.e. higher
> magnification in the image center means barrel distortion. Focal
> length and magnification are simply related, so there is no
> precise single focal length for most real life lenses.

Focal length is a matter of definition. And the only definition
that is independent of the viewframe is refractive behaviour
(magnification) close to the optical axis (paraxial), where a = tan
a = sin a = 2 tan a/2 = 2 sin a/2, i.e. the projection formula
doesn't matter anymore. Equally, a distortion model like r' = r
(ar^3 + br^2 + cr + 1) wouldn't matter either.

But as I said, Hugin additionally has this "-a-b-c" term, which
changes things. It mathematically transfers part of the paraxial
focal length into the distortion parameters, thus resulting in a
different focal length.

> This is most significant for fisheye lenses. The popular Samyang
> 8mm lens f.e. is even marketed as different focal length. You only
> can give an approximate value after you estimated the mapping
> formula:
> http://michel.thoby.free.fr/SAMYANG/Early%20test%20report.html

In this link, in the first plot, the focal length is the slope of
the lines at the origin.

BTW, I own the Samyang 8mm f/2.8, with a projection between
equidistant and stereographic. Here's the result of measurement:

assumed stereographic
a = 0.02036
b = -0.08028
c = 0.01446
FOV = 144.49°

Hugin measures a focal length of 8.04mm, but it is 8.4mm actually.
Due to distortion, the lens can see more than a perfect
stereographic lens should see. I think this is the reason why
Samyang markets it with a too short focal length.

This may also mean that Hugin's pooly defined focal length (in sense
of paraxial optics) blends nicely with manufacturers' habits, so it
is probably wise to leave it anyway. But I don't have much data. I
owned only one other fisheye, for which a+b+c vanished, so it was
not helpful in this regard. ;-)

Torsten Bronger

unread,
Apr 8, 2014, 2:32:49 PM4/8/14
to hugi...@googlegroups.com
Hallöchen!

Erik Krause writes:

> [...]
>
> This is most significant for fisheye lenses. The popular Samyang
> 8mm lens f.e. is even marketed as different focal length. You only
> can give an approximate value after you estimated the mapping
> formula:
> http://michel.thoby.free.fr/SAMYANG/Early%20test%20report.html

I performed a quite nice test with my Samyang 8mm f/2.8. If I
assume stereographic projection, I get

focal length = 8.04
a = 0.02036
b = -0.08028
c = 0.01446
==> real focal length = 8.41


However, assuming full-frame fisheye, the same control points yield

focal length = 8.65
a = 0.02142
b = -0.0194
c = 0.02785
==> real focal length = 8.39

I think this supports my view that Hugin's focal length, multiplied
by (1-a-b-c), results in the real one.

Erik Krause

unread,
Apr 8, 2014, 2:54:35 PM4/8/14
to hugi...@googlegroups.com
Am 08.04.2014 08:36, schrieb Torsten Bronger:
> But as I said, Hugin additionally has this "-a-b-c" term, which
> changes things. It mathematically transfers part of the paraxial
> focal length into the distortion parameters, thus resulting in a
> different focal length.

hugin inherited the lens model from panotools. There the -a-b-c term was
introduced to keep approximately the same image dimensions when
correcting distortions (an I assume Mr. Dersch did the right thing then,
he'S a professor for mathematics after all. However, the focal length is
for user convenience only since internally panotools works with the
field of view solely.

Erik Krause

unread,
Apr 8, 2014, 3:49:20 PM4/8/14
to hugi...@googlegroups.com
Am 08.04.2014 20:32, schrieb Torsten Bronger:

> I think this supports my view that Hugin's focal length, multiplied
> by (1-a-b-c), results in the real one.

Why do you want to know the focal length that precise? Lenses are
allowed to differ up to +/- 5% from the advertised focal length. Many
lenses change focal length during focusing. Most modern 100mm 1:1 macro
lenses f.e. have a near limit of 30cm, which means the focal length is
only 75mm at near limit. Who cares?

Torsten Bronger

unread,
Apr 8, 2014, 5:38:33 PM4/8/14
to hugi...@googlegroups.com
Hallöchen!

Erik Krause writes:

> Am 08.04.2014 20:32, schrieb Torsten Bronger:
>
>> I think this supports my view that Hugin's focal length,
>> multiplied by (1-a-b-c), results in the real one.
>
> Why do you want to know the focal length that precise?

In the Lensfun project, we need the exact focal length for
projection changes, e.g. from fisheye to rectilinear. 5% error is
the difference between straight lines and visibly bent lines.

The main problem -- and my main motivation for this thread -- is
documentation. Lensfun must exactly tell the user how everything is
defined. And Lensfun has this FOV data field inherited from Hugin.
I could just write "it's the value that Hugin provides", but I find
this sub-optimal. People may use other tools for calibration, or
use Lensfun's data in other tools.

Hugin's unfortunate definition of FOV/focal length forced us to
explain this data field in a lengthy and awkward way. Even worse,
Lensfun supports also non-Hugin distortion models, and for them, the
FOV refers to the correct focal length. Oh well ...

> Lenses are allowed to differ up to +/- 5% from the advertised
> focal length.

Yes, the actual mean value certainly differs, but I assume that the
deviation *within* one lens model is smaller (at least for modern
lens series). Besides, it is still senseful to have the correct
focal length in the first place. The errors add up after all.

> Many lenses change focal length during focusing. Most modern 100mm
> 1:1 macro lenses f.e. have a near limit of 30cm, which means the
> focal length is only 75mm at near limit.

We are aware of that at Lensfun, and we have specified that all
Lensfun data refers to focus @ infinity, if not stated otherwise.

Fabrice Kerzerho

unread,
Apr 16, 2014, 3:44:48 AM4/16/14
to hugi...@googlegroups.com
Thank you for those explanations, I think that precision is important when we have to batch a lot of panos; we need the accurate informations to get the same ratio px/degrees in the resulted pictures, in order to integrate real elements geo localized (with Gimp or blender for example); this should help me a lot:-)
Reply all
Reply to author
Forward
0 new messages