Oct 21, 2026 · Imaging · 8 min read

Building a Deterministic RAW-to-sRGB Image Pipeline in Python and Rust

When training vision models or archiving studio product photography, subtle color shifts between macOS Preview, Linux headless containers, and web browsers usually trace back to missing ICC profiles or resizing in gamma-encoded space rather than linear light.

Linear-Light Resampling Matters

Downsampling directly in sRGB darkens high-frequency edges and introduces moiré around fine mesh or woven textures. Converting 16-bit linear sensor data through a fixed camera-to-XYZ matrix, resizing with a Lanczos3 filter in linear float32 space, and applying the sRGB transfer function only as the final export step keeps outputs identical across platforms.

Explicit ICC Tagging

Never assume downstream viewers treat untagged PNG or WebP assets as sRGB. Always embed a standard compact sRGB ICC profile and verify pixel hashes in automated tests so library upgrades cannot silently alter white balance or chroma subsampling.