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.0-cp39-cp39-win_amd64.whl (857.9 kB view details)

Uploaded CPython 3.9Windows x86-64

odmrawpy-0.24.0-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.0-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.0-cp39-cp39-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

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

Uploaded CPython 3.9macOS 10.9+ x86-64

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

Uploaded CPython 3.8Windows x86-64

File details

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

File metadata

  • Download URL: odmrawpy-0.24.0-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.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ec4e79382872c1842d2e8c19a5e4f4ee28fc83a872cebe8406574f540f11d8e0
MD5 f28aec4a8b8a4ee25629ba8ad179496c
BLAKE2b-256 8a12c515eef8670b06b327c712b3ca9004bd52a785d7d9ce9fe42212204d50b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for odmrawpy-0.24.0-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.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for odmrawpy-0.24.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f65263bf2a960a9245fecc5fe94f007689e12cf06f163c8cc3dd9904a1303bf5
MD5 77a0bbc1fbbf50b952b8a5b0530c44aa
BLAKE2b-256 6b95a2ea271b94aee977af4ee7d6ce292e5a401cfb7f65d75de73af7a0d77a64

See more details on using hashes here.

Provenance

The following attestation bundles were made for odmrawpy-0.24.0-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.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for odmrawpy-0.24.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 884c949ae246b572196c24f907ec9922cb47c5215aa0ae9eb082511bcd3b398e
MD5 6c45c272a38a37d79d10f226e20556c6
BLAKE2b-256 5d96bb6708b55b24db61cc2fadd33d0a5913865042b15dd364711b2fa329184f

See more details on using hashes here.

Provenance

The following attestation bundles were made for odmrawpy-0.24.0-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.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for odmrawpy-0.24.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b9eee5e0c50ec5e7f1eabee71eac2f9a81743e435c33b0706a2869eb0de41fd8
MD5 b44764dbec1364a387a73d29cf33f658
BLAKE2b-256 8f058ea6eaa89369db3a1173fdd93030f7749f31b5d0b86201c011fa10b30acd

See more details on using hashes here.

Provenance

The following attestation bundles were made for odmrawpy-0.24.0-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.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for odmrawpy-0.24.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 671a8c0577cf22fb4f7e69503feb65c7488a729c3ec10b2510be879034933fec
MD5 3ae325f5739e517116622a192cc4e47d
BLAKE2b-256 2140e1b980ad53acfa523a66c7269a07d176987a6a8201a8b88e99ed0c58e2f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for odmrawpy-0.24.0-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.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: odmrawpy-0.24.0-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.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9bde6de751dc61df427f0250c1b42461fc071c22cdd1e11fdf11e297284fe511
MD5 5deb8c4f1358898391a09af6b46b7e69
BLAKE2b-256 8e1d262c3e714986c7d7b186e689e29ca333e73421082bcbfa73b7ffef90aff7

See more details on using hashes here.

Provenance

The following attestation bundles were made for odmrawpy-0.24.0-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.

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