---
title: 'RawGen: Diffusion-based Raw Image Generation'
url: https://www.emergentmind.com/topics/rawgen
type: topic
---

# RawGen: Diffusion-based Raw Image Generation

Searching arXiv for “RawGen” and closely related papers to ground the article with current citations.
{"query":"ti:RawGen OR all:RawGen", "max_results": 10}
Searching for inverse-ISP and raw image generation context to support positioning and related-work framing.
{"query":"all:\"inverse ISP\" OR all:\"raw image generation\" OR all:\"camera raw\"", "max_results": 10}
RawGen is a diffusion-based framework for learning camera raw image generation from either text prompts or sRGB inputs, producing scene-referred linear outputs in CIE XYZ and camera-specific raw representations for arbitrary target cameras [2604.00093]. It is presented as, to the authors’ knowledge, the first diffusion-based framework enabling text-to-raw generation for arbitrary target cameras, alongside sRGB-to-raw inversion. Its central premise is that large-scale sRGB diffusion priors can be repurposed into physically meaningful linear image generation by combining conditional denoising, a specialized decoder, and deterministic camera calibration derived from DNG metadata [2604.00093].

## 1. Problem setting and nomenclature

RawGen is motivated by the distinction between scene-referred raw images and display-referred sRGB images. Scene-referred raw data retains linear radiometric information about the scene and is the appropriate domain for denoising, demosaicing, HDR reconstruction, illuminant estimation, and learning ISPs, because white balance, exposure scaling, and tone mapping have physically meaningful interpretations only on linear signals. By contrast, sRGB outputs are 8-bit, nonlinear, and already entangled with gamma, tone curves, contrast, color styling, and other photo-finishing operations. Those properties make sRGB a poor substrate for physics-aware image analysis and restoration [2604.00093].

The practical obstacle is dataset scarcity. Large-scale raw datasets are limited, camera-specific, and coupled to proprietary in-camera ISP behavior. As a result, each new sensor or ISP variant typically requires new capture and relabeling, while existing diffusion models remain optimized for photo-finished sRGB imagery rather than scene-referred linear representations. Classical inverse-ISP methods assume a fixed pipeline and therefore struggle when the input has passed through diverse, unknown, and nonlinear photo-finishing stages [2604.00093].

The name “RawGen” also appears in unrelated literature. In one large-systems paper, “RawGen” is interpreted as Retrieval-Augmented Generation rather than raw-image generation, so the term is not unique across arXiv usage [2501.13881].

## 2. Core objectives and conceptual contributions

RawGen repurposes a large sRGB text-to-image prior to produce physically meaningful scene-referred outputs. Its first contribution is text-to-raw generation for arbitrary cameras: the framework generates linear CIE XYZ first, then deterministically maps that output to a target camera raw-RGB space using calibration metadata such as `ForwardMatrix` and `ColorMatrix` from DNG files. This design makes the linear synthesis camera-agnostic while still allowing camera-specific raw outputs without retraining [2604.00093].

Its second contribution is sRGB-to-raw inversion. Given an sRGB image containing unknown photo-finishing, RawGen uses image conditioning to invert the input to a canonical linear XYZ anchor, after which the result can be mapped to a device raw space if desired. The framework therefore addresses both generative and inverse formulations within the same latent-space pipeline [2604.00093].

A third contribution is the many-to-one inverse-ISP dataset. For each underlying scene, multiple sRGB renditions generated with diverse ISP and photo-finishing parameters are anchored to a single scene-referred target. This supervision explicitly teaches the model to suppress stylistic variability and recover the common linear representation. The authors describe the resulting outputs as camera-centric linear reconstructions that outperform fixed-ISP inverse methods on heterogeneous inputs [2604.00093].

A fourth contribution is methodological rather than purely architectural: RawGen is designed as a data source for downstream low-level vision. Text-driven synthetic raw generation is used to scale training data for illuminant estimation, raw denoising, and neural ISP training, with reported gains over prior synthetic sources [2604.00093].

## 3. Architecture and learning formulation

RawGen builds on a pretrained rectified-flow DiT with native image conditioning, specifically the FLUX.1-Kontext backbone. The framework operates in latent space. A frozen VAE encoder $E_{\mathrm{VAE}}$ encodes sRGB inputs into latents, while a specialized VAE decoder $D_{\mathrm{VAE}}$ is fine-tuned so that it decodes latents into linear CIE XYZ images rather than sRGB [2604.00093].

For sRGB-to-raw inversion, the input image is encoded into $z_{\mathrm{sRGB}}$, and those conditioning tokens are concatenated with noisy target tokens. The combined sequence is then jointly processed through the DiT with LoRA adapters on attention projections; only the target tokens are supervised. For text-to-raw generation, the framework uses the base model’s text-to-latent path to obtain $z_{\mathrm{sRGB}}$, and then runs the same conditional generation procedure to produce an XYZ latent. In both modes, the latent prediction stage is followed by XYZ decoding and then by deterministic camera-specific mapping [2604.00093].

The denoiser is trained with a rectified-flow $v$-prediction objective. Let $\epsilon \sim \mathcal{N}(0, I)$ and define the straight-line noising path
$$
z_t = (1 - t)\, z_{\mathrm{XYZ}} + t\, \epsilon, \quad t \in [0,1].
$$
The ground-truth velocity is
$$
v_{\mathrm{gt}} = \epsilon - z_{\mathrm{XYZ}},
$$
and the denoising loss is
$$
\mathcal{L}_{\mathrm{denoise}} =
\mathbb{E}_{k,\, t,\, \epsilon}
\left\|
v_{\mathrm{gt}} - v_{\theta}(z_t,\, t;\, z_{\mathrm{sRGB}^{(k)}})
\right\|_2^2.
$$
The decoder is fine-tuned with an $L_1$ reconstruction objective,
$$
\widehat{I}_{\mathrm{XYZ}} = D_{\mathrm{VAE}}(z_{\mathrm{XYZ}}), \qquad
\mathcal{L}_{\mathrm{rec}} =
\left\|
\widehat{I}_{\mathrm{XYZ}} - I_{\mathrm{XYZ}}
\right\|_1,
$$
which retargets the decoder from the sRGB domain to the XYZ domain while preserving spatial representation capacity [2604.00093].

## 4. Many-to-one inverse-ISP dataset and forward imaging model

The many-to-one dataset is central to RawGen’s invariance claim. For each raw scene, a canonical scene-referred target $x$ in CIE XYZ is derived by applying per-scene white balance and camera-to-XYZ conversion before any sRGB rendering. Multiple sRGB variants are then produced by varying white balance gains, tone mapping curves, and contrast around realistic ranges. The training set is therefore
$$
\mathcal{D} = \{(y_k,\, x) \mid k = 1,\dots,N\},
$$
where each $y_k = f_{\mathrm{ISP}}(x; \theta_k)$ is a different photo-finished rendition of the same underlying scene [2604.00093].

The representative forward ISP used to motivate the inverse problem begins from camera raw with black level $b$ and white balance gains $w = [w_R, w_G, w_B]^T$:
$$
\begin{aligned}
x_{\mathrm{wb}} &= \mathrm{diag}(w)\,(x_{\mathrm{raw}} - b), \\
x_{\mathrm{cam}} &= D(x_{\mathrm{wb}}), \\
x_{\mathrm{XYZ}} &= M_{\mathrm{cam}\rightarrow\mathrm{XYZ}}\,x_{\mathrm{cam}}, \\
x_{\mathrm{sRGB}} &= \Gamma\!\Big(T\big(M_{\mathrm{XYZ}\rightarrow\mathrm{sRGB}}\,x_{\mathrm{XYZ}}\big)\Big),
\end{aligned}
$$
where $D(\cdot)$ is demosaicing, $T(\cdot)$ is a tone map, and $\Gamma(\cdot)$ is the sRGB gamma or OETF. Optional modules include denoising, sharpening, gamut mapping, and contrast or saturation adjustments [2604.00093].

In the reproducibility details, the randomized photo-finishing process is specified more concretely. White balance uses red and blue gains sampled as $r,b \sim U(0.7,1.3)$, with green fixed at $1.0$. Tone mapping is applied per channel as
$$
T(E_i) = \frac{(1+\beta)\,E_i^{\gamma}}{\beta + E_i^{\gamma}},
\qquad
\beta \sim \mathcal{N}(0.6,0.1^2),\ 
\gamma \sim \mathcal{N}(0.9,0.1^2),
$$
and global contrast uses
$$
I_{\mathrm{out}} = (I_{\mathrm{in}} - 0.5)\, c + 0.5,
\qquad
c \sim U(0.7,1.3).
$$
This construction explicitly exposes the model to ISP and photo-finishing diversity while keeping the target scene-referred representation fixed [2604.00093].

## 5. Camera-specific mapping and inference modes

RawGen separates canonical linear generation from device-specific rendering by decoding into CIE XYZ first and only then mapping into the target camera’s raw-RGB space. The mapping uses DNG calibration metadata and interpolates matrices between two reference illuminants:
$$
g = \mathrm{clip}\!\left(
\frac{1/T - 1/T_1}{1/T_2 - 1/T_1},\, 0,\, 1
\right),
$$
$$
\mathbf{C}(T) = g\,\mathbf{C}_1 + (1-g)\,\mathbf{C}_2,
\qquad
\mathbf{F}(T) = g\,\mathbf{F}_1 + (1-g)\,\mathbf{F}_2.
$$
The decoded XYZ image is mapped to white-balanced camera RGB by
$$
I_{\mathrm{WB}} =
\mathrm{clip}\!\big(
\widehat{I}_{\mathrm{XYZ}} \cdot \mathbf{F}(T)^{-T},\, 0,\, 1
\big),
$$
the illuminant is converted as
$$
\boldsymbol{\ell}_{\mathrm{RGB}} = \mathbf{C}(T)\,\boldsymbol{\ell}_{\mathrm{XYZ}},
$$
and device raw-RGB is obtained through
$$
I_{\mathrm{raw}} =
\mathrm{clip}\!\big(
I_{\mathrm{WB}} \odot \boldsymbol{\ell}_{\mathrm{RGB}},\, 0,\, 1
\big).
$$
Optional heteroscedastic noise and CFA remosaicing can then be applied for more realistic raw outputs [2604.00093].

The sRGB-to-raw inversion mode takes an input image $y$, target camera $c$, and optional text prompt $p$, and first encodes the sRGB image as
$$
z_{\mathrm{sRGB}} = E_{\mathrm{VAE}}(y).
$$
It then integrates the reverse rectified-flow ODE conditioned on $z_{\mathrm{sRGB}}$:
$$
\hat{z}_{\mathrm{XYZ}} \approx z_1 + \int_{1}^{0}
v_{\theta}(z_t,\, t;\, z_{\mathrm{sRGB}})
\, \mathrm{d}t,
$$
decodes the scene-referred XYZ image, and maps it to the target camera’s raw-RGB. The text-to-raw mode replaces the image encoder stage with the base model’s text-to-latent path,
$$
z_{\mathrm{sRGB}} = \mathrm{Text2Latent}(p),
$$
after which the same conditional generation, decoding, and XYZ-to-raw mapping are used [2604.00093].

The implementation is intentionally lightweight in calibration requirements. The reported inputs are an sRGB image or a text prompt together with the target camera’s DNG metadata, and the paper states that using a single DNG file of the target camera suffices to obtain the required matrices [2604.00093].

## 6. Training setup and empirical evaluation

The training data combines the MIT-Adobe FiveK and RAISE raw DNG collections. XYZ anchors are computed using DNG `AsShotNeutral` and `ForwardMatrix`, while multiple sRGB variants are rendered with a physically grounded software ISP and randomized photo-finishing. The denoiser uses the FLUX.1-Kontext DiT backbone with LoRA of rank $r=64$ and $\alpha=64$ on attention projections; the decoder is fine-tuned to XYZ using $L_1$ loss. Training uses $1024 \times 1024$ crops, with XYZ anchors stored as 16-bit PNG and sRGB variants as 8-bit PNG [2604.00093].

In the many-to-one invertability evaluation based on FiveK expert-retouched variations from editors A–E, RawGen is reported to achieve the best CIE XYZ reconstruction across all five styles against CIE XYZ Net, InvISP, and Raw-Diffusion. The reported PSNR/SSIM examples are A: 23.20/0.8432, B: 24.35/0.8581, C: 23.37/0.8387, D: 23.51/0.8531, and E: 23.89/0.8500. Typical baselines are summarized as approximately 19–21 dB PSNR and approximately 0.78–0.84 SSIM, and an ablated one-to-one RawGen is described as substantially worse, which the authors use to highlight the role of many-to-one training [2604.00093].

The suppression of photo-finishing variability is also evaluated in latent space using PCA, t-SNE, and UMAP compactness over 100 graded variants per prompt. Mean distance to centroid is reported as PCA 160.0, t-SNE 10.69, and UMAP 1.067 for RawGen, compared with larger values for alternatives such as XYZNet and Raw-Diffusion. The paper interprets this as evidence that RawGen more strongly suppresses photo-finishing variability while preserving a common scene-referred anchor [2604.00093].

For device-specific synthesis, the decoded XYZ outputs are mapped to the Samsung Galaxy S24 main camera raw-RGB space with optional noise. Pre-trained neural ISPs trained only on real S24 data produce plausible sRGB from RawGen raw inputs without retraining, which the paper presents as an indicator of distribution alignment between the synthetic raw outputs and real-device raw data [2604.00093].

## 7. Downstream use, limitations, and significance

A major claim of RawGen is that synthetic raw data can improve downstream low-level vision systems. Using 3K generated samples and evaluating on real test splits, the paper reports gains over Graphics2RAW in three tasks. For illuminant estimation on NUS-8 with nine cameras, Graphics2RAW yields mean 4.21°, median 3.38°, and worst 25% 8.57°, whereas RawGen yields mean 3.14°, median 2.11°, and worst 25% 7.37°, approaching the real-data model at mean 3.02°, median 2.17°, and worst 25% 6.77°. For neural ISP training on a nighttime dataset, Graphics2RAW gives PSNR 38.10, SSIM 0.974, and $\Delta E$ 2.301, while RawGen gives PSNR 38.42, SSIM 0.970, and $\Delta E$ 2.183, comparable to training on real raw at PSNR 38.32, SSIM 0.974, and $\Delta E$ 2.133. For raw denoising, RawGen reports 50.63/0.994 at ISO 1600 and 48.57/0.992 at ISO 3200, compared with 49.37/0.991 and 48.16/0.989 for Graphics2RAW [2604.00093].

The reported advantages follow directly from the framework’s representation choice. By generating canonical XYZ, RawGen decouples scene synthesis from rendering, so white balance, exposure, and tone mapping remain reliable and camera-agnostic in the linear domain. Deterministic mapping to arbitrary camera raw spaces provides device-specific data without retraining, and optional noise plus CFA remosaicing makes the outputs suitable for raw-domain models. The use of text prompts further scales scene diversity without capture campaigns or graphics asset preparation [2604.00093].

The limitations are also explicit. Device fidelity beyond color remains incomplete, because accurate raw synthesis depends not only on color calibration but also on sensor noise, lens shading, point spread functions, and optical blur. RawGen currently injects heteroscedastic noise but does not model complex spatially varying characteristics. Inversion remains many-to-one, so extreme photo-finishing or heavy local edits can challenge recovery. Mapping quality also depends on correct DNG calibration; inaccurate or incomplete `ForwardMatrix` or `ColorMatrix` metadata degrades XYZ-to-raw accuracy. The paper therefore positions future work around richer device priors and learned physics for noise and optics [2604.00093].

Source: https://www.emergentmind.com/topics/rawgen