Skip to content

Commit

Permalink
Simplify fisheye effect and fix issue with distortion
Browse files Browse the repository at this point in the history
  • Loading branch information
Kidev committed Jan 20, 2025
1 parent 7da0eb6 commit 3546210
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,29 @@ def map_fisheye(self, i, j, width, height, dim, xcenter, ycenter):
yd = j - ycenter
rd = hypot(xd, yd)

rn = rd / (dim / 2)

theta = rn * (self.fov * pi / 360)

# See https://en.wikipedia.org/wiki/Fisheye_lens
if self.mapping == "equidistant":
ifoc = dim * pi / (self.fov * 180)
rr = rd * ifoc

r = theta
elif self.mapping == "equisolid":
ifoc = 2.0 * sin(self.fov * pi / 720)
rr = 2 * arctan(rd * ifoc / dim)

r = 2 * sin(theta / 2)
elif self.mapping == "orthographic":
ifoc = 2.0 * sin(self.fov * pi / 360)
rr = arctan(rd * ifoc / dim)

r = sin(theta)
elif self.mapping == "stereographic":
ifoc = 2.0 * tan(self.fov * pi / 720)
rr = 2 * arctan(rd * ifoc / (2 * dim))
r = 2 * tan(theta / 2)

r = r * (dim / 2)

rdmask = rd != 0

xs = xd.astype(np.float32).copy()
ys = yd.astype(np.float32).copy()

ofoc = dim / (2 * tan(self.pfov * pi / 360))
factor = ofoc * tan(rr)

xs[rdmask] = (factor[rdmask] / rd[rdmask]) * xd[rdmask] + xcenter
ys[rdmask] = (factor[rdmask] / rd[rdmask]) * yd[rdmask] + ycenter
xs[rdmask] = (r[rdmask] / rd[rdmask]) * xd[rdmask] + xcenter
ys[rdmask] = (r[rdmask] / rd[rdmask]) * yd[rdmask] + ycenter

xs[~rdmask] = xcenter
ys[~rdmask] = ycenter
Expand Down

0 comments on commit 3546210

Please sign in to comment.