Are my LibRaw / rawpy settings giving me true unprocessed sensor data for CIE 1931(XYZ) color space conversion?
I’m working on a project to measure object brightness from photographs as accurately as possible.
The plan:
Load RAW sensor data.
Extract pixels from a region of interest and average them.
Convert to XYZ color space and use the Y channel as brightness.
Since I’m using Python, I rely on rawpy (a wrapper for LibRaw). My main concern is whether the way I open/process RAW files preserves true, unprocessed sensor values, so that my XYZ conversion is valid and not influenced by hidden processing.
Here’s the code I’m using and extracting average XYZ value of a circular region:
with rawpy.imread(file_path) as raw:
rgb = raw.postprocess(
demosaic_algorithm=rawpy.DemosaicAlgorithm.LINEAR,
use_camera_wb=False,
user_wb=[1.0, 1.0, 1.0, 1.0],
output_color=rawpy.ColorSpace.sRGB,
no_auto_bright=True,
gamma=(1.0, 1.0),
output_bps=16
)
height, width, _ = rgb.shape
# Get circular region
cx = width // 2 + offset_x
cy = height // 2 + offset_y
pixels = []
for y in range(max(0, cy - radius), min(height, cy + radius)):
for x in range(max(0, cx - radius), min(width, cx + radius)):
if (x - cx)**2 + (y - cy)**2 <= radius**2:
pixels.append(rgb[y, x])
pixels = np.array(pixels)
avg_rgb = np.mean(pixels, axis=0)
# Normalize
avg_rgb_normilized = avg_rgb.astype(np.float32) / 65535.0
XYZ = colour.RGB_to_XYZ(
avg_rgb_normilized,
colour.RGB_COLOURSPACES['sRGB']
)
Questions:
Are these LibRaw/rawpy parameters ensuring I’m getting the closest possible to pure sensor data and after transformation to XYZ I have right values?
Side note: In testing, I’ve noticed that when a JPEG version of the image has fully clipped sRGB (255), the RAW still isn’t saturated — but the green channel rises disproportionately fast with small increases in light. Could this be quantum efficiency of camera sensor, white balance scaling, or something else?
I’m new to both LibRaw and color science, so any pointers or corrections would be greatly appreciated.
Recent comments