Skip to main content

RAW image processing for Python, a wrapper for libraw

Project description

rawpy is an easy-to-use Python wrapper for the LibRaw library. It also contains some extra functionality for finding and repairing hot/dead pixels.

API Documentation

Jupyter notebook tutorials

Sample code

Load a RAW file and save the postprocessed image using default parameters:

import rawpy
import imageio.v3 as iio

path = 'image.nef'
with rawpy.imread(path) as raw:
    rgb = raw.postprocess()
iio.imwrite('default.tiff', rgb)

Save as 16-bit linear image:

with rawpy.imread(path) as raw:
    rgb = raw.postprocess(gamma=(1,1), no_auto_bright=True, output_bps=16)
iio.imwrite('linear.tiff', rgb)

Extract embedded thumbnail/preview image and save as JPEG:

with rawpy.imread(path) as raw:
    # raises rawpy.LibRawNoThumbnailError if thumbnail missing
    # raises rawpy.LibRawUnsupportedThumbnailError if unsupported format
    thumb = raw.extract_thumb()
if thumb.format == rawpy.ThumbFormat.JPEG:
    # thumb.data is already in JPEG format, save as-is
    with open('thumb.jpeg', 'wb') as f:
        f.write(thumb.data)
elif thumb.format == rawpy.ThumbFormat.BITMAP:
    # thumb.data is an RGB numpy array, convert with imageio
    iio.imwrite('thumb.jpeg', thumb.data)

Find bad pixels using multiple RAW files and repair them:

import rawpy.enhance

paths = ['image1.nef', 'image2.nef', 'image3.nef']
bad_pixels = rawpy.enhance.find_bad_pixels(paths)

for path in paths:
    with rawpy.imread(path) as raw:
        rawpy.enhance.repair_bad_pixels(raw, bad_pixels, method='median')
        rgb = raw.postprocess()
    iio.imwrite(path + '.tiff', rgb)

Installation

Install rawpy by running:

pip install rawpy

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

Stable vs. pre-release

All stable rawpy releases are always built against a stable LibRaw library release. You can output the LibRaw version with print(rawpy.libraw_version).

rawpy pre-releases have version numbers like 0.15.0a1 and are built against a recent LibRaw snapshot. To install a pre-release, run:

pip install --pre rawpy

Optional features

The underlying LibRaw library supports several optional features. The following table shows which PyPI binary wheels support which features.

Feature Windows macOS Linux
LCMS color engine yes yes yes
RedCine codec yes yes yes
DNG deflate codec yes yes yes
DNG lossy codec yes yes yes
Demosaic Pack GPL2 no no no
Demosaic Pack GPL3 no no no
OpenMP yes no yes

Tip: You can dynamically query supported features by inspecting the rawpy.flags dictionary.

Note on GPL demosaic packs: The GPL2 and GPL3 demosaic packs are not included as rawpy is licensed under the MIT license which is incompatible with GPL.

Installation from source on Linux/macOS

For macOS, LibRaw is built as part of the rawpy build (see external/). For Linux, you need to install the LibRaw library on your system.

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

sudo apt-get install libraw-dev

Or install the latest release version from the source repository:

git clone https://github.com/LibRaw/LibRaw.git libraw
git clone https://github.com/LibRaw/LibRaw-cmake.git libraw-cmake
cd libraw
git checkout 0.20.0
cp -R ../libraw-cmake/* .
cmake .
sudo make install

After that, install rawpy using:

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

On Linux, if you get the error "ImportError: libraw.so: cannot open shared object file: No such file or directory" when trying to use rawpy, then do the following:

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

The LibRaw library is installed in /usr/local/lib (if installed manually) and apparently this folder is not searched for libraries by default in some Linux distributions.

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 rawpy.

In a PowerShell window:

$env:USE_CONDA = '1'
$env:PYTHON_VERSION = '3.7'
$env:PYTHON_ARCH = '64'
$env:NUMPY_VERSION = '1.14.*'
git clone https://github.com/letmaik/rawpy
cd rawpy
.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.

odmrawpy-0.24.1-cp39-cp39-win_amd64.whl (857.9 kB view details)

Uploaded CPython 3.9Windows x86-64

odmrawpy-0.24.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

odmrawpy-0.24.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

odmrawpy-0.24.1-cp39-cp39-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

odmrawpy-0.24.1-cp39-cp39-macosx_10_9_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

odmrawpy-0.24.1-cp38-cp38-win_amd64.whl (859.5 kB view details)

Uploaded CPython 3.8Windows x86-64

odmrawpy-0.24.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

odmrawpy-0.24.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

File details

Details for the file odmrawpy-0.24.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: odmrawpy-0.24.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 857.9 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for odmrawpy-0.24.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d1e8d036cd55984181e7ab0fc03303e5a5b636abe1b1c35660292f85d08dfd23
MD5 9ab2fa11aa21afc096325cec4819da0a
BLAKE2b-256 0f481eb6150cb51c5839bd36b63376a76de93fcd41925412bdbbc94638564c9e

See more details on using hashes here.

Provenance

The following attestation bundles were made for odmrawpy-0.24.1-cp39-cp39-win_amd64.whl:

Publisher: ci.yml on OpenDroneMap/rawpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odmrawpy-0.24.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for odmrawpy-0.24.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5736ebf64d30c110e01c2e59c076003fd05c50dbd764bb06696312a3eb2fce44
MD5 6044a6ea1397a6f5ec1aeabc4ee7aea1
BLAKE2b-256 0169cf59983edf43cd18266fb5288c37b3d2073e49ea9889da4ee92b604ccf9e

See more details on using hashes here.

Provenance

The following attestation bundles were made for odmrawpy-0.24.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on OpenDroneMap/rawpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odmrawpy-0.24.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for odmrawpy-0.24.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 051cd6d0c585a04c7e2398ba8aec49694148ba0d21bc99609aa6b4400acc105f
MD5 af0685c083b165b4a524c25a2a4bd693
BLAKE2b-256 f78238fd6e06ce40f44b02664c5436f3fda9c1ab2ef73aabcc687984d2016662

See more details on using hashes here.

Provenance

The following attestation bundles were made for odmrawpy-0.24.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: ci.yml on OpenDroneMap/rawpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odmrawpy-0.24.1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for odmrawpy-0.24.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3f94e3bad339a0243f19ac36391f643fee8a5534e95552aab8df08ff69e3fd66
MD5 dc05fb0c17face402f003691589121c5
BLAKE2b-256 cfcc7331b48d5aa3091ba41fb171126498ff2103757c875d73b879932fb95d5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for odmrawpy-0.24.1-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: ci.yml on OpenDroneMap/rawpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odmrawpy-0.24.1-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for odmrawpy-0.24.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 50b8d48ef2f62d9494db5dc4348d833b9ba8f72ec95797cb10699190f7a420e4
MD5 ebfe032d21cb191616ccdff7477b703d
BLAKE2b-256 d97c88f03e771722d5870d31105cd4a9194fe8c4071a5d35490f741a8ecdaa86

See more details on using hashes here.

Provenance

The following attestation bundles were made for odmrawpy-0.24.1-cp39-cp39-macosx_10_9_x86_64.whl:

Publisher: ci.yml on OpenDroneMap/rawpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odmrawpy-0.24.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: odmrawpy-0.24.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 859.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for odmrawpy-0.24.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 de0050b2f31c6aa618bc42f553477bc09e4810516d24151a968959b96291d1ad
MD5 2408a97b4ba59abc7f2628f0a90e9325
BLAKE2b-256 40b7b8e9d221a331ce2340ffdc354624306ddbfa1c4be16124926e13238628bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for odmrawpy-0.24.1-cp38-cp38-win_amd64.whl:

Publisher: ci.yml on OpenDroneMap/rawpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odmrawpy-0.24.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for odmrawpy-0.24.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5bd51461cf5c3855f53c8c229e07c2cc0feadf7177d80e48132188ca9cf22ee1
MD5 6c7e8eded7eec8c31ad607d844636475
BLAKE2b-256 6f98a0eb00e16ff17710982d89146fcb313e049a8b09f7f1314e62550a4283fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for odmrawpy-0.24.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on OpenDroneMap/rawpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odmrawpy-0.24.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for odmrawpy-0.24.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c673808efd8de55a1d12b658a24b43085277e9e71c8d438b0042c41e41de0a19
MD5 d763e6192091689e33941b6e7484e48d
BLAKE2b-256 9ded86d7922605910d07392f7e7b991aa326ac56e1669383288079ebdc0e35e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for odmrawpy-0.24.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: ci.yml on OpenDroneMap/rawpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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