letmaik/rawpy

📷 RAW image processing for Python, a wrapper for libraw

What it solves

Reading and processing camera RAW files (like .NEF, .CR2, .ARW, .DNG) in Python is cumbersome because the underlying LibRaw library is C-based and not directly usable from Python. rawpy solves this by providing an easy-to-use Python wrapper, so you can load a RAW file, postprocess it into a regular image, extract embedded thumbnails, and even find and repair hot or dead pixels — all with simple Python calls.

How it works

rawpy wraps the LibRaw library, which handles the decoding of many RAW formats. You open a RAW file with rawpy.imread() (usable as a context manager), call .postprocess() to convert the RAW sensor data into an RGB image, and save the result with any image library. The wrapper also exposes extra functions:

  • Thumbnail extraction: raw.extract_thumb() returns the embedded preview, either as JPEG bytes or as an RGB numpy array depending on the stored format.
  • Bad pixel handling: rawpy.enhance.find_bad_pixels() scans multiple RAW files to identify hot/dead pixels, and rawpy.enhance.repair_bad_pixels() can repair them using a median filter method.

rawpy ships pre-built binary wheels for Linux, macOS, and Windows (64-bit), and it supports optional features like the LCMS color engine, RedCine codec, DNG deflate/lossy codecs, and OpenMP (except on macOS). You can query which features are available at runtime via rawpy.flags. The README also explains a known Linux multiprocessing deadlock issue caused by OpenMP + fork and recommends using spawn or forkserver start methods.

Who it’s for

Python developers who work with digital camera RAW files — photographers, imaging pipelines, computer vision researchers, or anyone who needs to process RAW images programmatically. It’s also useful for people who need to recover or repair images with defective sensor pixels. The project provides API documentation and Jupyter notebook tutorials, so it suits both beginners and experienced users.

Highlights

  • Simple Python API: rawpy.imread() + postprocess() converts RAW to RGB in a few lines
  • Extracts embedded thumbnails/previews as JPEG or bitmap
  • Finds and repairs hot/dead pixels using multiple RAW files
  • Pre-built wheels for Linux, macOS, and Windows (64-bit)
  • Optional features (LCMS color engine, RedCine, DNG codecs, OpenMP) and runtime feature inspection via rawpy.flags
  • Clear guidance on known issues like multiprocessing deadlocks with OpenMP

Related

  • Project
  • Project
  • Project
  • Project