RawPy class
- class rawpy.RawPy
Load RAW images, work on their data, and create a postprocessed (demosaiced) image.
All operations are implemented using numpy arrays.
- close(self) None
Release all resources and close the RAW image.
Consider using context managers for the same effect:
with rawpy.imread('image.nef') as raw: # work with raw object
- extract_thumb(self) Thumbnail
Extracts and returns the thumbnail/preview image (whichever is bigger) of the opened RAW image as
rawpy.Thumbnailobject. For JPEG thumbnails, data is a bytes object and can be written as-is to file. For bitmap thumbnails, data is an ndarray of shape (h,w,c). If no image exists or the format is unsupported, an exception is raised.- Return type:
- postprocess(self, params: Params | None = None, **kw) NDArray[np.uint8]
Postprocess the currently loaded RAW image and return the new resulting image as numpy array.
- Parameters:
params (rawpy.Params) – The parameters to use for postprocessing.
**kw –
Alternative way to provide postprocessing parameters. The keywords are used to construct a
rawpy.Paramsinstance. If keywords are given, then params must be omitted.
- Return type:
ndarray of shape (h,w,c)
- raw_color(self, int row, int column) int
Return color index for the given coordinates relative to the full RAW size. Only usable for flat RAW images (see raw_type property).
- raw_value(self, int row, int column) ushort
Return RAW value at given position relative to the full RAW image. Only usable for flat RAW images (see
raw_typeproperty).
- raw_value_visible(self, int row, int column) ushort
Return RAW value at given position relative to visible area of image. Only usable for flat RAW images (see
raw_typeproperty).
- set_unpack_params(self, int shot_select: int = 0) None
Set parameters that affect RAW image unpacking.
This should be called after opening a file and before unpacking.
Note
This is a low-level method. When using
rawpy.imread(), unpack parameters can be provided directly.- Parameters:
shot_select (int) – select which image to extract from RAW files that contain multiple images (e.g., Dual Pixel RAW). Default is 0 for the first/main image.
- auto_whitebalance
RawPy.auto_whitebalance: Optional[List[float]]
White balance coefficients used during postprocessing.
This property returns the actual white balance multipliers that were used during postprocessing, regardless of the white balance mode: whether from camera settings, auto white balance calculation, user-specified values, or daylight balance.
This property must be accessed after calling
postprocess()ordcraw_process()to get the coefficients that were actually applied. If accessed before postprocessing, it returns None.This corresponds to LibRaw’s
imgdata.color.pre_mul[]array after processing, which contains the white balance multipliers applied to the raw sensor data.- Return type:
list of length 4, or None if postprocessing hasn’t been called yet
- black_level_per_channel
RawPy.black_level_per_channel: List[int]
Per-channel black level correction.
- Return type:
list of length 4
- camera_white_level_per_channel
RawPy.camera_white_level_per_channel: Optional[List[int]]
Per-channel saturation levels read from raw file metadata, if it exists. Otherwise None.
- Return type:
list of length 4, or None if metadata missing
- camera_whitebalance
RawPy.camera_whitebalance: List[float]
White balance coefficients (as shot). Either read from file or calculated.
- Return type:
list of length 4
- color_desc
RawPy.color_desc: bytes
String description of colors numbered from 0 to 3 (RGBG,RGBE,GMCY, or GBTG). Note that same letters may not refer strictly to the same color. There are cameras with two different greens for example.
- color_matrix
RawPy.color_matrix: NDArray[np.float32]
Color matrix, read from file for some cameras, calculated for others.
- Return type:
ndarray of shape (3,4)
- daylight_whitebalance
RawPy.daylight_whitebalance: List[float]
White balance coefficients for daylight (daylight balance). Either read from file, or calculated on the basis of file data, or taken from hardcoded constants.
- Return type:
list of length 4
- lens
RawPy.lens: Lens
- num_colors
RawPy.num_colors: int
Number of colors. Note that e.g. for RGBG this can be 3 or 4, depending on the camera model, as some use two different greens.
- other
RawPy.other: Other
- raw_colors
RawPy.raw_colors: NDArray[np.uint8]
An array of color indices for each pixel in the RAW image. Equivalent to calling raw_color(y,x) for each pixel. Only usable for flat RAW images (see raw_type property).
- Return type:
ndarray of shape (h,w)
- raw_colors_visible
RawPy.raw_colors_visible: NDArray[np.uint8]
Like raw_colors but without margin.
- Return type:
ndarray of shape (hv,wv)
- raw_image
RawPy.raw_image: NDArray[np.uint16]
View of RAW image. Includes margin.
For Bayer images, a 2D ndarray is returned. For Foveon and other RGB-type images, a 3D ndarray is returned. Note that there may be 4 color channels, where the 4th channel can be blank (zeros).
Modifying the returned array directly influences the result of calling
postprocess().Warning
The returned numpy array can only be accessed while this RawPy instance is not closed yet, that is, within a
withblock or before callingclose(). If you need to work on the array after closing the RawPy instance, make sure to create a copy of it withraw_image = raw.raw_image.copy().- Return type:
ndarray of shape (h,w[,c])
- raw_image_visible
RawPy.raw_image_visible: NDArray[np.uint16]
Like raw_image but without margin.
- Return type:
ndarray of shape (hv,wv[,c])
- raw_pattern
RawPy.raw_pattern: Optional[NDArray[np.uint8]]
The smallest possible Bayer pattern of this image.
- Return type:
ndarray, or None if not a flat RAW image
- raw_type
RawPy.raw_type: RawType
Return the RAW type.
- Return type:
- rgb_xyz_matrix
RawPy.rgb_xyz_matrix: NDArray[np.float32]
Camera RGB - XYZ conversion matrix. This matrix is constant (different for different models). Last row is zero for RGB cameras and non-zero for different color models (CMYG and so on).
- Return type:
ndarray of shape (4,3)
- sizes
RawPy.sizes: ImageSizes
Return a
rawpy.ImageSizesinstance with size information of the RAW image and postprocessed image.
- tone_curve
RawPy.tone_curve: NDArray[np.uint16]
Camera tone curve, read from file for Nikon, Sony and some other cameras.
- Return type:
ndarray of length 65536
- white_level
RawPy.white_level: int
Level at which the raw pixel value is considered to be saturated.
Additional low-level methods:
- class rawpy.RawPy
Load RAW images, work on their data, and create a postprocessed (demosaiced) image.
All operations are implemented using numpy arrays.
- dcraw_make_mem_image(self)
Return the postprocessed image (see
dcraw_process()) as numpy array.Note
This is a low-level method, consider using
postprocess()instead.- Return type:
ndarray of shape (h,w,c)
- dcraw_make_mem_thumb(self)
Return the thumbnail/preview image (see
unpack_thumb()) asrawpy.Thumbnailobject. For JPEG thumbnails, data is a bytes object and can be written as-is to file. For bitmap thumbnails, data is an ndarray of shape (h,w,c). If no image exists or the format is unsupported, an exception is raised.Note
This is a low-level method, consider using
extract_thumb()instead.- Return type:
- dcraw_process(self, params: Params | None = None, **kw) None
Postprocess the currently loaded RAW image.
Note
This is a low-level method, consider using
postprocess()instead.- Parameters:
params (rawpy.Params) – The parameters to use for postprocessing.
**kw –
Alternative way to provide postprocessing parameters. The keywords are used to construct a
rawpy.Paramsinstance. If keywords are given, then params must be omitted.
- open_buffer(self, fileobj: BinaryIO) None
Opens the given RAW image file-like object. Should be followed by a call to
unpack().Note
This is a low-level method, consider using
rawpy.imread()instead.- Parameters:
fileobj (file) – The file-like object.
- open_file(self, str path: str) None
Opens the given RAW image file. Should be followed by a call to
unpack().Note
This is a low-level method, consider using
rawpy.imread()instead.- Parameters:
path (str) – The path to the RAW image.
- unpack(self) None
Unpacks/decodes the opened RAW image.
Note
This is a low-level method, consider using
rawpy.imread()instead.
- unpack_thumb(self) None
Unpacks/decodes the thumbnail/preview image, whichever is bigger.
Note
This is a low-level method, consider using
extract_thumb()instead.