RAW image processing for Python, a wrapper for libraw
Actively maintained. Last release 4 weeks ago, commits in 5 of the last 26 weeks. A safe choice.
pip install rawpyrawpy is an easy-to-use Python wrapper for the LibRaw library. It also contains some extra functionality for finding and repairing hot/dead pixels.
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 dynamically loaded LibRaw version with . The version of the LibRaw headers used to compile rawpy is available as .
