Package: rawpy
rawpy is an easy-to-use Python wrapper for theLibRaw library.
It also contains some extra functionality for finding and repairing hot/dead pixels.API DocumentationJupyter notebook tutorialsSample codeLoad a RAW file and save the postprocessed image using defaultparameters:importrawpyimportimageiopath='image.nef'withrawpy.imread(path)asraw:rgb=raw.postprocess()imageio.imsave('default.tiff',rgb)Save as 16-bit linear image:withrawpy.imread(path)asraw: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:withrawpy.imread(path)asraw:# raises rawpy.LibRawNoThumbnailError if thumbnail missing# raises rawpy.LibRawUnsupportedThumbnailError if unsupported formatthumb=raw.extract_thumb()ifthumb.format==rawpy.ThumbFormat.JPEG:# thumb.data is already in JPEG format, save as-iswithopen('thumb.jpeg','wb')asf:f.write(thumb.data)elifthumb.format==rawpy.ThumbFormat.BITMAP:# thumb.data is an RGB numpy array, convert with imageioimageio.imsave('thumb.jpeg',thumb.data)Find bad pixels using multiple RAW files and repair them:importrawpy.enhancepaths=['image1.nef','image2.nef','image3.nef']bad_pixels=rawpy.enhance.find_bad_pixels(paths)forpathinpaths:withrawpy.imread(path)asraw:rawpy.enhance.repair_bad_pixels(raw,bad_pixels,method='median')rgb=raw.postprocess()imageio.imsave(path+'.tiff',rgb)InstallationInstall rawpy by running:pipinstallrawpy64-bit binary wheels are provided for Linux, macOS, and Windows.Stable vs. pre-releaseAll stable rawpy releases are always built against a stable LibRaw library release.
You can output the LibRaw version withprint(rawpy.libraw_version).rawpy pre-releases have version numbers like0.15.0a1and are built against
a recent LibRaw snapshot. To install a pre-release, run:pipinstall--prerawpyOptional featuresThe underlyingLibRaw librarysupports several optional features.
The following table shows which PyPI binary wheels support which features.FeatureWindowsmacOSLinuxLCMS color engineyesyesyesRedCine codecyesyesyesDNG deflate codecyesyesyesDNG lossy codecyesyesyesDemosaic Pack GPL2nononoDemosaic Pack GPL3nononoOpenMPyesnoyesTip: You can dynamically query supported features by inspecting therawpy.flagsdictionary.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/macOSFor 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:sudoapt-getinstalllibraw-devOr install the latest release version from the source repository:gitclonehttps://github.com/LibRaw/LibRaw.gitlibraw
gitclonehttps://github.com/LibRaw/LibRaw-cmake.gitlibraw-cmakecdlibraw
gitcheckout0.20.0
cp-R../libraw-cmake/*.
cmake.
sudomakeinstallAfter that, install rawpy using:gitclonehttps://github.com/letmaik/rawpycdrawpy
pipinstallnumpycython
pipinstall.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"|sudotee/etc/ld.so.conf.d/99local.conf
sudoldconfigThe 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 WindowsThese 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.*'gitclonehttps://github.com/letmaik/rawpycdrawpy
.github/scripts/build-windows.ps1The above will download all build dependencies (including a Python installation)
and is fully configured through the four environment variables.
SetUSE_CONDA = '0'to build within an existing Python environment.