rawpy Documentation

repository·main·Indexed 19 days ago

https://github.com/letmaik/rawpy

A Python wrapper for the LibRaw library providing RAW image processing. It allows users to load RAW files, postprocess them into RGB images, extract embedded thumbnails, and identify or repair bad pixels using the rawpy.enhance module. The library includes a RawPy class for image interaction, a Params class for pipeline configuration, and various enumeration classes for type-safe configuration of demosaicing algorithms and color spaces.

Tokens
5.5K
Snippets
19
Records
34
Agent score
73%

What's inside rawpy

  1. Distinguish between LibRawFatalError and LibRawNonFatalError

    main

    LibRaw errors are categorized into two main types based on their severity:

    1. rawpy.LibRawFatalError: Represents critical failures that prevent further processing. Subtypes include:

      • rawpy.LibRawUnsufficientMemoryError
      • rawpy.LibRawDataError
      • rawpy.LibRawIOError
      • rawpy.LibRawCancelledByCallbackError
      • rawpy.LibRawBadCropError
      • rawpy.LibRawTooBigError
      • rawpy.LibRawMemPoolOverflowError
    2. rawpy.LibRawNonFatalError: Represents errors that may not stop the entire process but indicate specific issues. Subtypes include:

      • rawpy.LibRawUnspecifiedError
      • rawpy.LibRawFileUnsupportedError
      • rawpy.LibRawRequestForNonexistentImageError
      • rawpy.LibRawOutOfOrderCallError
      • rawpy.LibRawNoThumbnailError
      • rawpy.LibRawUnsupportedThumbnailError
      • rawpy.LibRawInputClosedError
      • rawpy.LibRawNotImplementedError
  2. Check supported features in rawpy

    main
    The underlying LibRaw library supports various features like LCMS color engine, RedCine codec, and OpenMP. You can dynamically check which features are enabled in your current installation by inspecting the rawpy.flags dictionary.
  3. Use rawpy Enumerations for configuration

    main

    The rawpy library uses several enumeration classes to provide type-safe configuration options for raw processing tasks. When calling methods that require specific modes or types, use these enums instead of raw integers or strings.

    Available enumeration classes include:

    • rawpy.RawType: Defines the type of raw data.
    • rawpy.ThumbFormat: Specifies the format of the embedded thumbnail.
    • rawpy.DemosaicAlgorithm: Selects the algorithm used for demosaicing.
    • rawpy.ColorSpace: Defines the color space for processing.
    • rawpy.HighlightMode: Configures how highlights are handled.
    • rawpy.FBDDNoiseReductionMode: Configures the FBDD noise reduction mode.
  4. Use the RawPy class

    main
    The RawPy class is the primary interface for interacting with raw image data. It provides methods to access raw image properties and manipulate the image data using LibRaw. Refer to the RawPy symbol documentation for specific method signatures and usage details.
  5. Build rawpy wheels locally

    main

    To build platform-specific wheels locally, use the provided scripts in the .github/scripts/ directory.

    • Linux: .github/scripts/build-linux.sh (should be run inside a manylinux container)
    • macOS: .github/scripts/build-macos.sh
    • Windows: .github/scripts/build-windows.ps1
  6. Install rawpy in development mode

    main

    To set up a development environment, clone the repository, initialize submodules, and install dependencies. You can install rawpy in editable mode, which will automatically build LibRaw from the git submodules and compile the Cython extension (recommended for macOS/Windows).

    Prerequisites

    • Python: 3.9 or higher
    • Git: For cloning and submodules
    • C/C++ Compiler:
      • Linux: GCC
      • macOS: Xcode Command Line Tools
      • Windows: Visual Studio 2017 or higher

    Setup Steps

    1. Clone and initialize submodules:
      git clone https://github.com/letmaik/rawpy.git
      cd rawpy
      git submodule update --init
    2. Install Python dependencies:
      pip install -r dev-requirements.txt
    3. Build and install in editable mode:
      pip install -e .

    Note for Linux users: If you prefer using a system-installed LibRaw instead of building from source, install libraw-dev and pkg-config via your package manager (e.g., sudo apt-get install libraw-dev) before running pip install -e ..

    git clone https://github.com/letmaik/rawpy.git
    cd rawpy
    git submodule update --init
    pip install -r dev-requirements.txt
    pip install -e .
  7. Start working with RAW images using rawpy.imread

    main

    The primary entry point for processing RAW images is the rawpy.imread function. Calling this function returns a rawpy.RawPy object, which serves as the central handle for all subsequent image processing operations (such as debayering, post-processing, or extracting metadata).

    import rawpy
    
    # Load a RAW image
    raw = rawpy.imread('image.ARW')
    
    # All further operations are performed on the 'raw' object
  8. Install rawpy from source on Linux/macOS

    main

    On macOS, LibRaw is built as part of the rawpy build. On Linux, you must install the LibRaw library on your system first.

    Linux (Ubuntu) steps:

    1. Install LibRaw development files (note: apt versions may be outdated):

      sudo apt-get install libraw-dev

      Alternatively, build the latest LibRaw from source as described in the README.

    2. Install rawpy from source:

      git clone https://github.com/letmaik/rawpy
      cd rawpy
      pip install numpy cython
      pip install .

    Troubleshooting Linux Library Loading: If you encounter ImportError: libraw.so: cannot open shared object file, ensure /usr/local/lib is in your library path:

    echo "/usr/local/lib" | sudo tee /etc/ld.so.conf.d/99local.conf
    sudo ldconfig
  9. Build and view documentation locally

    main

    The project uses Sphinx for documentation. To build the HTML documentation and view it locally:

    1. Build the documentation:
      sphinx-build -b html docs dist-docs
    2. **Serve the documentation**:
       ```bash
    python -m http.server --directory dist-docs 8000

    Then access it at http://localhost:8000.

    sphinx-build -b html docs dist-docs
    python -m http.server --directory dist-docs 8000