Skip to main content

Lens distortion correction for Python, a wrapper for lensfun

Project description

lensfunpy is an easy-to-use Python wrapper for the lensfun library.

API Documentation

Sample code

How to find cameras and lenses:

import lensfunpy

cam_maker = 'NIKON CORPORATION'
cam_model = 'NIKON D3S'
lens_maker = 'Nikon'
lens_model = 'Nikkor 28mm f/2.8D AF'

db = lensfunpy.Database()
cam = db.find_cameras(cam_maker, cam_model)[0]
lens = db.find_lenses(cam, lens_maker, lens_model)[0]

print(cam)
# Camera(Maker: NIKON CORPORATION; Model: NIKON D3S; Variant: ;
#        Mount: Nikon F AF; Crop Factor: 1.0; Score: 0)

print(lens)
# Lens(Maker: Nikon; Model: Nikkor 28mm f/2.8D AF; Type: RECTILINEAR;
#      Focal: 28.0-28.0; Aperture: 2.79999995232-2.79999995232;
#      Crop factor: 1.0; Score: 110)

How to correct lens distortion:

import cv2 # OpenCV library

focal_length = 28.0
aperture = 1.4
distance = 10
image_path = '/path/to/image.tiff'
undistorted_image_path = '/path/to/image_undist.tiff'

im = cv2.imread(image_path)
height, width = im.shape[0], im.shape[1]

mod = lensfunpy.Modifier(lens, cam.crop_factor, width, height)
mod.initialize(focal_length, aperture, distance)

undist_coords = mod.apply_geometry_distortion()
im_undistorted = cv2.remap(im, undist_coords, None, cv2.INTER_LANCZOS4)
cv2.imwrite(undistorted_image_path, im_undistorted)

It is also possible to apply the correction via SciPy instead of OpenCV. The lensfunpy.util module contains convenience functions for RGB images which handle both OpenCV and SciPy.

How to correct lens vignetting:

import lensfunpy
import imageio

db = lensfun.Database()
cam = db.find_cameras('NIKON CORPORATION', 'NIKON D3S')[0]
lens = db.find_lenses(cam, 'Nikon', 'Nikkor AF 20mm f/2.8D')[0]

img = imageio.imread('/path/to/image.tiff')

focal_length = 20
aperture = 4
distance = 10
width = img.shape[1]
height = img.shape[0]

mod = lensfunpy.Modifier(lens, cam.crop_factor, width, height)
mod.initialize(focal_length, aperture, distance)

did_apply = mod.apply_color_modification(img)
if did_apply:
    imageio.imwrite('corrected.tiff', img)
else:
    print('vignetting not corrected, calibration data missing?')

Installation

Install lensfunpy by running:

pip install lensfunpy

64-bit binary wheels are provided for Linux, macOS, and Windows.

Installation from source on Linux/macOS

If you have the need to use a specific lensfun version or you can’t use the provided binary wheels then follow the steps in this section to build lensfunpy from source.

First, install the lensfun library on your system.

On Ubuntu, you can get (an outdated) version with:

sudo apt-get install liblensfun-dev

Or install the latest developer version from the Git repository:

git clone https://github.com/lensfun/lensfun
cd lensfun
cmake .
sudo make install

After that, install lensfunpy using:

git clone https://github.com/letmaik/lensfunpy
cd lensfunpy
pip install numpy cython
pip install .

On Linux, if you get the error “ImportError: liblensfun.so.0: cannot open shared object file: No such file or directory” when trying to use lensfunpy, then do the following:

echo "/usr/local/lib" | sudo tee /etc/ld.so.conf.d/99local.conf
sudo ldconfig

The lensfun library is installed in /usr/local/lib when compiled from source, and apparently this folder is not searched for libraries by default in some Linux distributions. Note that on some systems the installation path may be slightly different, such as /usr/local/lib/x86_64-linux-gnu or /usr/local/lib64.

Installation from source on Windows

These instructions are experimental and support is not provided for them. Typically, there should be no need to build manually since wheels are hosted on PyPI.

You need to have Visual Studio installed to build lensfunpy.

In a PowerShell window:

$env:USE_CONDA = '1'
$env:PYTHON_VERSION = '3.7'
$env:PYTHON_ARCH = 'x86_64'
$env:NUMPY_VERSION = '1.14.*'
git clone https://github.com/letmaik/lensfunpy
cd lensfunpy
.github/scripts/build-windows.ps1

The above will download all build dependencies (including a Python installation) and is fully configured through the four environment variables. Set USE_CONDA = '0' to build within an existing Python environment.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

lensfunpy-1.14.0-cp312-cp312-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.12Windows x86-64

lensfunpy-1.14.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

lensfunpy-1.14.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

lensfunpy-1.14.0-cp312-cp312-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.12macOS 10.9+ x86-64

lensfunpy-1.14.0-cp311-cp311-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.11Windows x86-64

lensfunpy-1.14.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lensfunpy-1.14.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

lensfunpy-1.14.0-cp311-cp311-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

lensfunpy-1.14.0-cp310-cp310-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.10Windows x86-64

lensfunpy-1.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lensfunpy-1.14.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

lensfunpy-1.14.0-cp310-cp310-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

lensfunpy-1.14.0-cp39-cp39-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.9Windows x86-64

lensfunpy-1.14.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

lensfunpy-1.14.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

lensfunpy-1.14.0-cp39-cp39-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

lensfunpy-1.14.0-cp38-cp38-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.8Windows x86-64

lensfunpy-1.14.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

lensfunpy-1.14.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

lensfunpy-1.14.0-cp38-cp38-macosx_10_9_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

File details

Details for the file lensfunpy-1.14.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: lensfunpy-1.14.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for lensfunpy-1.14.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 461ece274066cd86130faabe60374b2531a784e35e5940c6aa321fbb977ee8ff
MD5 08089c423204819537a1b8d105db19fc
BLAKE2b-256 953046608b939ebdfba483d1e331da1765489fd0d95dedb7b5c6b0e64e7288a9

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.14.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c59f76b16cff085335a7be2ad77d23130117ecf70a72c3d1318028c9e9b0d6f0
MD5 b1c346019790e85822e9d2637df7a606
BLAKE2b-256 be7bbc900901f0c5afe264153ea2923cf3ab3da1d52a788ff8ae9981bd81507a

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.14.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 360e5f401db5a9e9c8d0aab9d82113ba0d24beb6a1140fa5baebab67d76ee1fa
MD5 7dfcef44081c7726b95052a10749be7d
BLAKE2b-256 1c8abd8209bee4b62fbea2809ff056d1cd4789d27861a1b04a6312b4854ba1d5

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.14.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 006780b905d14bd597755532a687a481a8209bf7adc21ef0bb127333a5aff24e
MD5 268ae1e480b190f3810d64f68f5f0f8e
BLAKE2b-256 3435f0e108d946cd6b370f1522e2a371ae88a6540332f7c53f01d74f805d1d65

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: lensfunpy-1.14.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for lensfunpy-1.14.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4242a82ced668c5da5b433b84199abbf8ed8d59429a64e26fe1630d608cf6409
MD5 6fb52a4c6b1d485b9cd9f8f234faa378
BLAKE2b-256 671ec2745cdd890f4ba6085108661d55697e36ca00d1f812a64f1a47f4340d15

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.14.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e482fd9371e9c7c97f7ecebb05e4a022fada9967b40b8f7283fa98c5ec73e72b
MD5 40484fab5bb2f00aa2cec6ac7118d84c
BLAKE2b-256 db8146e316cd227088ada4d46e28e7c5aff7a380e55ffcee4ab1612ffaf6cea8

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.14.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d4b5677926d870ec12472b70f8f3a3754a04d079e7b64993bb9115c39ce893a5
MD5 0fb726c50d408c48692f1e7b687ae5e2
BLAKE2b-256 dd47b70dd6693a56aa709fe8d0539aa1a0189f0670744c807ca2f2d0d40dcda1

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.14.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d320d258ce57b87da8d925935b4eaa78459b9c63cd2b0888de9ea22c83c1ee0d
MD5 0b1efee3c6aaae9a6bd25fdf4220bdea
BLAKE2b-256 2d19ec7ec1d89616bc2e3a96dd4dfbb471aba695c5523f746ea6410eb073f982

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: lensfunpy-1.14.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for lensfunpy-1.14.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 485397d08a4ffbc510a43eea4fac07d4fe86eb0b28218054023e7679881d3ca0
MD5 9c7c545c52cf0302d4889b747654de3b
BLAKE2b-256 b4f6287f04ec8d82399df1b78bcbd80fba070662bccfc5df26bd0a368028a777

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 17d797322b5d0bafad1910c41992b855c7ace1730d6c71ded4e551d96a0148cd
MD5 264d5c821c83ee956cfca8aa613046ac
BLAKE2b-256 04d33ed4259da9db9056e6068dbd4f056f2368d36ae2a1d6bfcc99c7aac1612e

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.14.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a1189a91f4d4e3121eed634674d6e385ab27420c3686b200dd736ff762438366
MD5 efe451110f908e3ada10a604c86b9e37
BLAKE2b-256 8f2f6cbc21615d89b40ee6ee89ae736719c323f7f9c847661b45bdf581713d8a

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.14.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3e7977c0f8fb7626c3ee6842969dc14a0d00f7ccf19d1c52a335fb2a30fb43fb
MD5 2f3eed93d1cd205391e57cb5366125a3
BLAKE2b-256 4404aac955515658212bb0a003dc6271ca4330994a803584401512ce18c70dc1

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: lensfunpy-1.14.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for lensfunpy-1.14.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 92ed17f28083eedc3a9b9287aba7b38f52130d60997f854eb14b55b17182e4ba
MD5 0218f424dc089c88d7b5fc0f0ddf86e9
BLAKE2b-256 d61e141b919ab9b1a1049be2759354c57a01dbeaf80a2f0da105eef91f229844

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.14.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b199d29ea9c06a35e366b1d1f214e2dacfa1fed7ee5600077f0682ed250d5547
MD5 caf8eed1bf58b18d9d402ce767f30915
BLAKE2b-256 746801c6c3d12c10a47eb177f1e3355803b9fe7e2850ee59eb43d12aa571cc14

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.14.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a86f7d2050a3a85a4a3ba78417331f1ecf33ac9802817a12b2c55d457524c5e2
MD5 ba0e0a8433d793b2edad575a56527853
BLAKE2b-256 09783867e0d34edf7490e8ceff3bbfd51306bc574b0836f701dc0dc26fc15648

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.14.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c4a1876e975bb4a4d2126ceb9c4ce3feaf368b78e22eceeba0dae16b82d2b74b
MD5 b6062337ab9a2f4c1a085f440e74b6be
BLAKE2b-256 1cf631bfecbec3a679dd121fb5a5a11089d20ed1b617637f27395449fe646745

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: lensfunpy-1.14.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for lensfunpy-1.14.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 ebff565b64c18b8e06f2e9be1e1d8197cecd7506616c072e2747657617cb5a75
MD5 cebefdac4f23b8afd658114a73637142
BLAKE2b-256 47ea0f737fd549d22f158aaccc0eee517958625b5e7f80974ea442452a996af0

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.14.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2b6cdea6d1908696d8a586164c7363c205b2c48c117bcc80182ee78108afb11a
MD5 03a7dbe95c5e7c3266ec071cba74d09d
BLAKE2b-256 4af695b4b02959b7ae0203a79af2c5933d9765a8ad830ef47546cbcc20e4ef2e

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.14.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a32e2f027c1b05506db4228eeeefcc860737678e96873700ec721f811e718004
MD5 e9c3dd9e1efa27fda09a3e77ad27442b
BLAKE2b-256 9147222c386c6d07a0e3dff8db793cf6ae46c131172d1c0a3bd01ba961944875

See more details on using hashes here.

File details

Details for the file lensfunpy-1.14.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.14.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3d3ca18386abecc8577d8a15aee52653f1af3adb447b473518de82a8e311bf2d
MD5 fb8b2245b0c9ef6046dfc1cd6b68573c
BLAKE2b-256 0dc6fa453a538d9eb5f0acb2f0a272f31505881c73dfb620352f02a9cdffade5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page