defish fully manual lens

I got myself a Meike 7.5mm f/2.8 micro 4/3 lens for fun. It is not in the Lensfun database, and has no electronic contacts.

I am wondering if there is a way to defish the image manually (ie by eyeballing the result), either in (preferred) or outside Darktable, using FOSS on Linux. The lens correction module sliders are greyed out in Darktable.

1 Like

If you have a photo of a grid, eg a brick wall taken face-on, we can take a look.

If the lens is close to an ideal equidistant fisheye, an atan() transformation will make it rectilinear. A Windows BAT script to do this with ImageMagick is:

FOR /F "usebackq" %%L ^
IN (`magick identify ^
  -format "WW4=%%[fx:4*w]\nHH4=%%[fx:4*h]\nW4m1=%%[fx:4*w-1]\nH4m1=%%[fx:4*h-1]" ^
  %SRC%`) ^
DO set %%L

set RAT=3.1

magick ^
  -size 1x%HH4% ^
  gradient:black-white ^
  ( +clone ^
    -fx "atan(%RAT%*u)/atan(%RAT%)" ^
  ) ^
  -compose Mathematics -define compose:args=0,0.5,-0.5,0.5 -composite ^
  -scale "%WW4%x%HH4%^!" ^
  +depth ^
  dispmap.png

magick ^
  %SRC% ^
  -virtual-pixel Black ^
  -define distort:scale=4 ^
  -distort Depolar -1 ^
  dispmap.png ^
  -compose Displace ^
    -set option:compose:args 0x%H4m1% ^
    -composite ^
  -background Pink -virtual-pixel Background ^
  -define distort:scale=0.25 ^
  -distort Polar -1 ^
  %OUTFILE%

This takes an input image %SRC% and makes an output image %OUTFILE%. There is only one parameter, RAT, a number. For a GoPro camera, this is 3.1.

If you know the angle alpha captured from corner to corner, then:

RAT = tan (alpha / 2)

The commands above supersample the image by a factor of 4. It creates a displacement map which can be reused for any other inputs. Gory details are at De-barrel distortion: De-fisheye.

2 Likes

It also occurs to me that the Hugin toolset might do the job. Take a couple or three overlapping photos and throw these at Hugin, and it might figure out the geometric transformation that makes them match. I’ve never tried this, and I’m not a Hugin expert.

1 Like

Another possibility: Fred Weinhaus has a bash script (using ImageMagick) to convert a fisheye image to rectilinear. Unlike my code above, Fred’s can cope with different types of fisheye: linear, equalarea, orthographic, or stereographic.

See Fred's ImageMagick Scripts: FISHEYE2RECT

Thanks for all the suggestions. Apparently Hugon has a GUI tool, I will try to take some images of a rectilinar-looking object and then add the lens to LensFun.

Hugin was how I was able to generate a DCP profile for a Mi Sphere 360 camera - I saved a reference image in RawTherapee and then defished it using Hugin before feeding to dcamprof.

It should also be (IIRC) possible to build a lensfun profile from Hugin calibration parameters that can be manually selected/applied. I’m pretty sure Hugin’s distortion model is identical to one of lensfun’s.

1 Like