• Stars
    star
    481
  • Rank 91,384 (Top 2 %)
  • Language Cython
  • License
    MIT License
  • Created about 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📷 RAW image processing for Python, a wrapper for libraw

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

path = 'image.nef'
with rawpy.imread(path) as raw:
    rgb = raw.postprocess()
imageio.imsave('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)
imageio.imsave('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
    imageio.imsave('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()
    imageio.imsave(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.

More Repositories

1

pyvirtualcam

🎥 Send frames to a virtual camera from Python
C++
330
star
2

lensfunpy

📷 Lens distortion correction for Python, a wrapper for lensfun
Cython
127
star
3

vscode-git-tree-compare

🎄 VS Code extension for comparing the git working tree against a branch, tag, or commit, displayed as folder tree
TypeScript
48
star
4

node-virtualcam

🎥 Send frames to a virtual camera from Node.js
C
43
star
5

monadiccp

Monadic Constraint Programming framework
Haskell
26
star
6

evolutionary-container-loading

Container loading with evolutionary algorithms in Scala
Scala
20
star
7

rawpy-notebooks

A collection of Jupyter notebooks using rawpy
Jupyter Notebook
19
star
8

xndarray

▦ Multidimensional arrays with semantics in JavaScript
JavaScript
8
star
9

gwt-phantomjs-junit-runstyle

A GWT JUnit run style for local testing with PhantomJS
Java
7
star
10

pixelpitch

Lists current cameras with their physical pixel sizes (pixel pitch)
Python
5
star
11

hungrymonkey

🎮 The Hungry Monkey Game
JavaScript
5
star
12

meeting-backgrounds

🖼️ Download and manage meeting background collections.
Python
5
star
13

PSExercise

▶️ YouTube videos on a schedule
PowerShell
4
star
14

chip8

🕹 CHIP-8 emulator written in AssemblyScript
TypeScript
4
star
15

crowfood

Creates dependency files from C/C++ code for creating dependency graphs with snakefood
Python
3
star
16

pixelart

🎨 My pixel art
3
star
17

valijson-wasm

valijson in the browser
HTML
2
star
18

playingcards-rooms

🎲 Custom rooms for playingcards.io
2
star
19

hungrypuffin

🎮 The Hungry Puffin Game
TypeScript
2
star
20

leafy

🍁 A minigame about leaves
C#
2
star
21

profviewer

🩺 Online viewer for runtime profiles.
JavaScript
2
star
22

gwt-webdriver-junit-runstyle

A GWT JUnit run style for remote testing via WebDriver's JSON over HTTP protocol
Java
1
star
23

exhaust

🌌 Exhaustively enumerate a combinatorial space
Python
1
star
24

ld-trace

ld --trace-symbol, but better.
Python
1
star
25

vscode-metalevel-references

VS Code extension that adds "Find All References" to the file and folder level
TypeScript
1
star
26

lensfunx

Experiments with lensfun
Python
1
star
27

rna-and-adp-wiki

A wiki about RNA folding basics and ADP implementations.
1
star
28

sweetdreams-netvibes-theme

Adaptation of iGoogle's "Sweet Dreams" theme for netvibes
1
star