Apply built-in lens correction for Nikon 24-70 F4 S

It looks this lens has built-in correction parameters that are applied automatically by software like LightRoom and Nikon Capture/NX View. I’m wondering would it be possible to do something similar with RawTherapee? Without this correction I see large geometric distortions just like described on DXO Mark site:

“So it isn’t really surprising to see that without its built-in corrections, the Nikkor Z zoom has rather high barrel distortion at 24mm and displays high pincushion distortion at 70mm.”

There is an old tutorial for adding a new lens to the lensfun database:

https://wilson.bronger.org/lens_calibration_tutorial/

I guess I can try following this and try to add 24-70 F4 S.

There is a new tutorial that is lovely contributed by @asn. If the tutorial is unclear, please let us know so we can clarify/update it.

PIXLS.US - Create lens calibration data for lensfun

Thanks a lot, will take a look!

Small typo:

You can move (step backward on forward) between shots to keep the 1/3rd rule above consistent.

More typos:

I probably only makes sense for prime lenses used for portrait or macro photography. However this is not required, the above it absolutely enough.

lensfun already has distorsion profile for this lens. You may need to download updated profile data using lensfun-update-data

Great news! Last time I did not find this command even though I have lensfun package installed. I guess I’ll download the source code and build the lib myself.

OK, downloaded the latest lensfun sources, built and installed. Ran the update Python script. Now I can see my lens in 2 files:

~/.local/share/lensfun/updates/version_1/mil-nikon.xml: Nikkor Z 24-70mm f/4 S

~/.local/share/lensfun/updates/version_2/mil-nikon.xml: Nikkor Z 24-70mm f/4 S

But the lens is not recognized automatically in RT and when I tried to select it manually I don’t it listed. I guess I need somehow to tell RT to look for the new lensfun database?

Yes, you need to build RT against your new lens fun version.

Built and installed lensfun from its sources:

$ find /usr/local -name *lensfun*
/usr/local/share/lensfun
/usr/local/share/lensfun/version_2/lensfun-database.xsd
/usr/local/share/lensfun/version_2/lensfun-database.dtd
/usr/local/lib64/liblensfun.so.2
/usr/local/lib64/liblensfun.so.0.3.95
/usr/local/lib64/pkgconfig/lensfun.pc
/usr/local/lib64/liblensfun.so
/usr/local/bin/g-lensfun-update-data
/usr/local/bin/lensfun-update-data
/usr/local/bin/lensfun-convert-lcp
/usr/local/bin/lensfun-add-adapter
/usr/local/include/lensfun
/usr/local/include/lensfun/lensfun.h
/usr/local/lib/python3.7/site-packages/lensfun-0.3.95-py3.7.egg-info
/usr/local/lib/python3.7/site-packages/lensfun

Then I got sources for RT Release 5.7, but cmake does not see lensfun:

t_build$ cmake -DCMAKE_BUILD_TYPE=“release” -DCACHE_NAME_SUFFIX="" -DPROC_TARGET_NUMBER=“2” -DBUILD_BUNDLE=“ON” -DBUNDLE_BASE_INSTALL_DIR="$HOME/programs/rawtherapee" -DOPTION_OMP=“ON” …/RawTherapee/
– The C compiler identification is GNU 9.2.1
– The CXX compiler identification is GNU 9.2.1
– Check for working C compiler: /usr/lib64/ccache/cc
– Check for working C compiler: /usr/lib64/ccache/cc – works
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Detecting C compile features
– Detecting C compile features - done
– Check for working CXX compiler: /usr/lib64/ccache/c++
– Check for working CXX compiler: /usr/lib64/ccache/c++ – works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Detecting CXX compile features
– Detecting CXX compile features - done
– CMAKE_BUILD_TYPE: release
– Found PkgConfig: /usr/bin/pkg-config (found version “1.6.1”)
– Checking for module ‘gtk±3.0>=3.16’
– Found gtk±3.0, version 3.24.11
– Checking for module ‘gtkmm-3.0>=3.16’
– Found gtkmm-3.0, version 3.24.1
– Checking for module ‘glib-2.0>=2.44’
– Found glib-2.0, version 2.60.7
– Checking for module ‘glibmm-2.4>=2.44’
– Found glibmm-2.4, version 2.60.1
– Checking for module ‘cairomm-1.0’
– Found cairomm-1.0, version 1.12.0
– Checking for module ‘gio-2.0>=2.44’
– Found gio-2.0, version 2.60.7
– Checking for module ‘giomm-2.4>=2.44’
– Found giomm-2.4, version 2.60.1
– Checking for module ‘gthread-2.0>=2.44’
– Found gthread-2.0, version 2.60.7
– Checking for module ‘gobject-2.0>=2.44’
– Found gobject-2.0, version 2.60.7
– Checking for module ‘sigc+±2.0>=2.3.1’
– Found sigc+±2.0, version 2.10.2
– Checking for module ‘lensfun>=0.2’
– Package ‘lensfun’, required by ‘virtual:world’, not found
CMake Error at /usr/share/cmake/Modules/FindPkgConfig.cmake:457 (message):
A required package was not found
Call Stack (most recent call first):
/usr/share/cmake/Modules/FindPkgConfig.cmake:642 (_pkg_check_modules_internal)
CMakeLists.txt:322 (pkg_check_modules)

– Configuring incomplete, errors occurred!
See also “/home/andrew/soft/rt_build/CMakeFiles/CMakeOutput.log”.
See also “/home/andrew/soft/rt_build/CMakeFiles/CMakeError.log”.

Looks I solved it by installing Fedora official packages for RT and lensfun (not building from sources) and then copying over the updated LF db:

sudo cp /home/andrew/.local/share/lensfun/updates/version_2/mil-nikon.xml /usr/share/lensfun/version_1

Now Z6 is recognized automatically and I can select the lens manually.

Thanks everybody for the help!

I am not sure how good of an idea is to copy a ‘version_2’ file in a ‘version_1’ lensfun DB. Just check that some other things are not broken or that you really get the things you want corrected and not something else.

You are right, I recopied from version_1 to version_1 just to be safe.

Thanks!

I have a problem building RawTherapee when lensfun is also built from source code. By default lensfun built from source code is installed in /usr/local. So I run cmake for RT as:

cmake -DCMAKE_BUILD_TYPE=“release” -DCACHE_NAME_SUFFIX=“5-dev” -DPROC_TARGET_NUMBER=“2” -DBUILD_BUNDLE=“ON” -DBUNDLE_BASE_INSTALL_DIR="$HOME/programs/rawtherapee" -DOPTION_OMP=“ON” -DLENSFUNDBDIR=/usr/local …/RawTherapee

and I get an error:

  • Checking for module ‘lensfun>=0.2’
    – Package ‘lensfun’, required by ‘virtual:world’, not found
    CMake Error at /usr/share/cmake/Modules/FindPkgConfig.cmake:457 (message):
    A required package was not found

So how do I specify lensfun location for RT when lensfun is installed in /usr/local?

Is the database in /use/local? Its probably in a sub dir.

I cannot point RT to lensfun if it is installed in /usr/local when lensfun is built from source code. Something in RT cmake configs insists on having lensfun-devel package to be installed. Otherwise I have this error:

– Checking for module ‘lensfun>=0.2’
– Package ‘lensfun’, required by ‘virtual:world’, not found
CMake Error at /usr/share/cmake/Modules/FindPkgConfig.cmake:457 (message):
A required package was not found

But the official lensfun-devel package is not the latest and does not have the lensfun-update-data command. So I have to have another lensfun installation, this time built from source code.

Then I can run /usr/local/bin/lensfun-update-data which updates data files in my home directory:

Successfully updated the database in /home/andrew/.local/share/lensfun/updates/version_1.
Successfully updated the database in /home/andrew/.local/share/lensfun/updates/version_2.

Then in RT I can manually select Nikon Z6 and 24-70 f/4 S and corrections are applied.

Phew! That’s a long process and now I have 2 installations of lensfun, but it seems it works. Maybe I need to talk to lensfun maintainers for Fedora and ask why the command to update the database is not included in the official package.

This was implemented by @agriggio in issue Update RawPedia with lensfun info · Issue #4074 · Beep6581/RawTherapee · GitHub , maybe he can help.

Are you sure the cmake target doesn’t need to point to this folder?

As a workaround you can edit the options file. There is a key at the end which you can use:

[Lensfun]
DBDirectory=