Skip to content

Add a camera profile calibration wizard with validated named profiles - #1342

Open
QuirkyTurtle94 wants to merge 3 commits into
storytold:mainfrom
QuirkyTurtle94:codex/camera-profile-wizard
Open

QuirkyTurtle94 wants to merge 3 commits into
storytold:mainfrom
QuirkyTurtle94:codex/camera-profile-wizard

Conversation

@QuirkyTurtle94

Copy link
Copy Markdown
Contributor

Adds the #1315 calibration wizard to the Photo menu and Profile panel. Users can build profiles from a folder, selection or current collection, compare whole-photo holdout results, install multiple named profiles per camera, and choose a profile for a photo or selection.

  • Runs locally in a cancellable background job, with bounded sampling and memory-gated decoding. No uploads.
  • Holds out every fifth usable distinct RAW. Installation requires improvement or an explicit override.
  • Saves profile choices in catalog/XMP edits with undo; supports model defaults and reversible removal/restoration. Missing choices use a diagnosed built-in fallback.
  • Includes profile identity in decoded, rendered and offline smart-preview caches; reload needs no restart.

Builds on #1332 (starting-colour provenance). Optional aggregate-pair export remains dependent on #1319; camera-style metadata is not exposed yet, so the wizard guides manual separation and warns about mixed styles.

Validation: full repository CI, headless UI inspection, and a local-only 12-RAW smoke test. Eleven RAWs were usable (9 training, 2 holdout); RMS was 0.031405 → 0.031377, a small difference, not evidence of a material colour-quality gain. Install/default/remove/restore were exercised in an isolated temporary profile folder. Repeating with the installed profile as baseline produced equal error and correctly required an explicit override. No photographs are included.

Closes #1315.

QuirkyTurtle94 and others added 3 commits October 12, 2026 20:32
Locate the Unix test child through PATH, preserve physical-file fault injection across case aliases, handle APFS filename restrictions, and account for the Apple Photos export row. Reuse the test-only fixes from local commit 3fd5d82.

Co-authored-by: Codex <noreply@openai.com>
…anels

Carry accepted colour and tone provenance from decoding to the selected photo in native and browser views. Distinguish validated local and built-in profiles, per-photo and partial fits, file matrices, spectral colour, and neutral fallback without changing pixels or cache versions.

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>

@radialmonster radialmonster left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The install gate doesn't yet tell a useful profile apart from noise. On six bodies, the interleaved held-out RMS reported an improvement while held-out ΔE00 against the camera JPEG got worse on independent frames.

Setup: PR head cf89102 with a local-only test harness that calls profile_pairs, fit_profile and the same render as validation_rms. The profile folder was empty, so "current" is the per-photo camera-JPEG fit on these bodies. I used about 1000 RAWs from six bodies: GX85, G9M2, G85, Rebel XSi, R7 and ILCE-1.

The files were split by session/date folder. The PR's every-fifth holdout ran inside one half of the folders. The other half, plus CC0 files from other photographers, served as the independent test.

ΔE00 was computed per pixel on the validation proxy: linear Rec.2020 to Lab D65, against the embedded JPEG (read as Adobe RGB where tagged). It measures agreement with the camera's style, not absolute accuracy.

PR-style profiles (46 to 125 training files) passed the gate on 5 of 6 bodies, with RMS gains of 0.1 to 4%. Mean ΔE00 on the independent frames:

  • GX85: 4.08 to 4.53 (other sessions), 4.43 to 4.71 (other photographers)
  • G9M2: 2.48 to 2.77 (other sessions), 1.04 to 1.45 (other photographers)
  • R7: 2.26 to 3.64 (other photographers)
  • Rebel XSi: 3.61 to 3.59 (other sessions), 2.28 to 3.06 (other photographers, 2 files)
  • G85: 3.40 to 3.38 (other sessions), 3.42 to 3.40 (other photographers)
  • ILCE-1 failed the gate (0.02145 to 0.02157); its other sessions went 1.73 to 2.00.

Minimum-size runs (5 training files and 1 holdout, 16 random draws per body):

  • The gate passed in 38 of 96 runs.
  • All 38 of the profiles that passed were worse on the independent frames, by ΔE00 +0.11 to +1.47 (median +0.53).
  • None of the 96 runs improved the independent frames, so pass or fail was unrelated to the outcome.

Inline comments cover the leakage-prone split, the metric, a lens-alignment regression on rebase, camera ids travelling in the Profile copy group, a shared "allow worse" box, and a global cache revision that breaks 5 tests and invalidates every photo on any install.

Also:

  • Picture style is only warned about, never checked.
  • The wizard and missing-profile strings bypass i18n::tr.
  • On this base, cargo test shows 5 new media/files failures (listed inline). The other 20 engine and 6 ui-egui failures also fail at the parent commit on Windows.

}
impl Validated {
pub fn improves(&self) -> bool {
self.holdout > 0 && self.before.is_finite() && self.after.is_finite() && self.after < self.before

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after < before with no margin and as few as 1 held-out photo lets noise through.

I ran 96 trials across six bodies, each with 5 training files and 1 held-out photo. This gate passed 38 times, and all 38 of those profiles were worse on independent frames of the same body (ΔE00 against the camera JPEG, +0.11 to +1.47). The median RMS change on the held-out photo was 0.0006, far below photo-to-photo spread.

Suggestion:

  • Require a minimum holdout, for example 10 or more photos from 3 or more sessions.
  • Require a paired per-photo improvement with a margin, for example most held-out photos improve and the mean gain exceeds its standard error, rather than a strict comparison of two means.

models.entry(model.clone()).or_insert_with(|| Training { baseline: crate::camera_profiles::resolved(&model), ..Default::default() });
// Split only usable, distinct whole files. None of a holdout file's pairs enter training.
group.usable += 1;
if group.usable.is_multiple_of(5) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking every fifth usable file in path order keeps burst and same-scene neighbours on both sides of the split. Dedup is exact-bytes only, so near-duplicates still leak.

Example: an R7 set of 56 chart frames from one session, plus 3 other frames.

  • The holdout passed the gate (RMS 0.02375 to 0.02281), and ΔE00 on the held-out frames barely moved (2.19 to 2.23).
  • On R7 files from other photographers, the same profile went from 2.26 to 3.64.

On the four bodies with many sessions, splitting by date folder showed a worse independent result than the interleaved holdout suggested. For example, on GX85 the holdout ΔE00 went from 5.22 to 5.31, but other sessions went from 4.08 to 4.53.

Suggestion: hold out whole sessions, grouped by capture date or time gaps, or by folder, instead of interleaved files.

// Display-referred RMS: encode both sides identically.
let a = a.clamp(0.0, 1.0).powf(1.0 / 2.2);
let b = f64::from(*b).clamp(0.0, 1.0).powf(1.0 / 2.2);
squared += (a - b).powi(2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Display-gamma RGB RMS and perceptual error disagree here:

  • GX85 holdout: this RMS improved (0.06242 to 0.06226) while mean ΔE00 on the same pixels got worse (5.22 to 5.31).
  • Rebel XSi: RMS 0.03082 to 0.03079, ΔE00 2.69 to 2.93.

Gamma RGB RMS is dominated by bright, low-chroma pixels and treats the same error alike in any channel and hue. Since this number decides installation, the gate should use ΔE00 (or at least ΔE in Lab) on the valid proxy pixels, reported with its per-photo spread.

Also, for bodies without a bundled profile, before is the holdout photo's own camera-JPEG fit, so the comparison is against an in-sample per-photo fit. That's a fair baseline, but the UI should say so.

return Err("RAW grew beyond the calibration limit".into());
}
let mut raw = lightcraft_raw::decode(&bytes).map_err(|e| e.to_string())?;
raw.opcodes.list3.retain(|op| !op.is_lens_correction());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads-up for the rebase: on main, camera_profiles::Pool::add computes lens_geometry(&raw.opcodes.list3) before stripping the lens opcodes and passes it to profile_pairs(raw, bytes, lens), so the sensor proxy lines up with lens-corrected camera JPEGs.

This path strips the opcodes and fits without that alignment. After a rebase, the wizard's pairs would drift from what Pool::add builds on lens-corrected bodies. Reusing Pool::add (or the same lens_geometry call) for both training and validation keeps them identical.

if training.files < 5 || training.holdout.is_empty() {
warn(
report,
format!("{model}: {} usable RAWs; need at least 5 training photos plus whole-photo holdout (select 7 or more).", training.usable),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small mismatch: 6 usable RAWs already pass (5 training, with the 5th as holdout), but the message says "select 7 or more". With the strict gate, 6 files also means a single held-out photo decides installation (see the comment on improves).

/// Starting-colour camera profile: empty uses the model default, `builtin` bypasses local
/// overrides, or a content-addressed local profile id. Kept separately from creative looks.
#[serde(skip_serializing_if = "String::is_empty")]
pub camera: String,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camera lives in the Profile settings group (SettingsGroup::Profile = ["profile"]), so copy/paste, presets and sync carry it. Checked with extract_groups and apply_partial:

  • Copying the Profile group from a photo with a local profile gives {"profile":{"amount":100.0,"camera":"cp-…","id":"lc.color"}}. Pasting writes that cp- id onto any target, including another body. cameraProfile.choose refuses other models, but paste bypasses that check, and the target then renders with the built-in fallback plus a missing-profile note.
  • The reverse also fails: a "Model default" photo serialises without camera, so pasting it onto a photo set to builtin leaves builtin in place.

Suggestion: skip camera on paste when the model differs, and serialise an explicit empty choice when copying.

}
h.finish().0 as u64
})
.wrapping_add(REVISION.load(std::sync::atomic::Ordering::Acquire))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVISION is global and goes into media::decoded_key for every photo. Installing, removing or changing the default for one body therefore changes the key of every photo in the catalogue: source_ref_with forgets their decoded sources, and every thumbnail cache key changes, including JPEGs and other cameras. Scoping the revision per model, for example a hash of the resolved profile for p's model, would avoid re-decoding everything.

It also makes tests order-dependent. With a parallel cargo test -p lightcraft-engine on this branch, these fail:

  • media::tests::worker_provenance_requires_a_current_source_and_is_forgotten
  • media::tests::decoder_info_survives_render_jobs_cache_and_eviction
  • media::tests::has_source_follows_what_the_session_accepted
  • media::tests::old_relative_white_balance_on_a_kelvin_camera_keeps_its_look_and_learns_the_as_shot_white
  • files::tests::quick_jobs_show_embedded_previews_then_cached_renders

All five pass when run alone and pass at the parent commit. They fail because the store and command tests call reload() mid-run.

register(ui.ctx(), format!("field:calibrationName:{}", result.profile.model), response.rect);
let name = name.clone();
if !result.improves() {
ui.checkbox(&mut state.allow_worse, "Allow installing a profile that did not improve");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state.allow_worse is one bool shared by every model's result. Ticking it under one model that didn't improve also enables "Install named profile" for every other model in the same run that didn't improve, and sends allowWorse: true for them. A per-model map, like state.names, would keep the override explicit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Camera profile wizard: build, check and choose per-model, per-style profiles from your own photos (GUI for calibrate)

2 participants