LR-PROF-CAMERACOLOR: leave pixels clipped in the camera JPEG out of the vignetting share

The sensor clip mask misses highlights the JPEG clips and the raw doesn't; their
JPEG brightness no longer follows the scene, so they skewed the measured share.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Martin JaniczekandClaude Opus 5.5 committed 2026-11-11 14:48:05 +01:00
1 parent 09e3840f1f
commit 33cdc22af5
3 files changed
+17 -6

No files matched your search

+8 -2
View File
@@ -357,6 +357,11 @@ const NEUTRAL_CHROMA: f64 = 0.03;
/// Fewest pixels a chromaticity class needs to take part in [`camera_vignetting_amount`].
const MIN_CLASS_PIXELS: usize = 32;
/// Camera JPEG level at or above which a channel counts as clipped in [`camera_vignetting_amount`], as for the colour
/// pairs (`pairs::colour_pair`): the JPEG's brightness no longer follows the scene there, whether or not the sensor
/// clipped too ([`SENSOR_CLIP`]).
const JPEG_CLIP: f32 = 0.98;
/// The chromaticity class of a sensor pixel in [`camera_vignetting_amount`]: 0 near-neutral, else 1 + its hue sector.
fn chromaticity_class(p: [f64; 3]) -> usize {
let p = p.map(|v| v.max(0.0));
@@ -381,7 +386,8 @@ fn chromaticity_class(p: [f64; 3]) -> usize {
/// ranks across hues would read that as vignetting: the correlation is taken within classes of similar sensor
/// chromaticity ([`chromaticity_class`]), averaged by their pixel counts. Within a class the camera's rendering is
/// taken as alike: two saturations of one hue that it renders differently, one gathered toward the corners, can still
/// read as vignetting. Clipped, black and non-finite pixels are left out. Proxies of different sizes, or fewer than
/// read as vignetting. Pixels clipped on the sensor (`clipped`) or in the JPEG ([`JPEG_CLIP`]), black and non-finite
/// pixels are left out. Proxies of different sizes, or fewer than
/// [`MIN_VIGNETTING_PIXELS`] usable pixels, keep the whole correction.
pub(super) fn camera_vignetting_amount(
sensor: &Rgb32f,
@@ -397,7 +403,7 @@ pub(super) fn camera_vignetting_amount(
let usable = |p: &[f32; 3]| p.iter().all(|v| v.is_finite()) && luminance_2020(*p) > 0.0;
let mut classes: Vec<Vec<(f64, [f64; 3], [f64; 3])>> = vec![Vec::new(); HUE_SECTORS + 1];
for (i, ((s, r), g)) in sensor.data.iter().zip(&reference.data).zip(gains).enumerate() {
if clipped.get(i).copied().unwrap_or(false) || !usable(s) || !usable(r) {
if clipped.get(i).copied().unwrap_or(false) || !usable(s) || !usable(r) || r.iter().any(|v| *v >= JPEG_CLIP) {
continue;
}
let s = s.map(f64::from);
+7 -2
View File
@@ -2834,7 +2834,8 @@ fn the_vignetting_gain_of_a_framed_proxy_is_taken_where_its_pixels_come_from() {
/// What `camera_vignetting_amount` can't measure on keeps the whole correction: proxies of different sizes, and a flat
/// scene, where every share ranks alike (a tie keeps the larger share, the correction a camera JPEG usually has).
/// Clipped and black pixels are left out: here they sit where the correction would brighten or darken them most and
/// would pull the share of a JPEG without any correction up. Non-finite pixels don't spoil the measurement.
/// would pull the share of a JPEG without any correction up. A JPEG clips highlights the sensor doesn't, so pixels
/// clipped in the JPEG are left out without the sensor's clip mask too. Non-finite pixels don't spoil the measurement.
#[test]
fn camera_vignetting_amount_falls_back_and_leaves_out_what_it_cannot_measure() {
use lightcraft_develop::EmbeddedVignette;
@@ -2878,7 +2879,11 @@ fn camera_vignetting_amount_falls_back_and_leaves_out_what_it_cannot_measure() {
let amount = measure(&sensor, &clipped_reference, &corners);
assert!(amount < 0.051, "clipped pixels are left out: measured {amount}");
let amount = measure(&sensor, &clipped_reference, &unclipped);
assert!(amount > 0.1, "the clipped pixels would have pulled the share up: {amount}");
assert!(amount < 0.051, "pixels clipped in the JPEG alone are left out: measured {amount}");
let mut bright_reference = reference.clone();
bright_reference.data.iter_mut().zip(&corners).filter(|(_, c)| **c).for_each(|(p, _)| *p = [0.97; 3]);
let amount = measure(&sensor, &bright_reference, &unclipped);
assert!(amount > 0.1, "the same pixels, just below the clip, would have pulled the share up: {amount}");
// the quarter it brightens least, black in the JPEG
let mut dark_reference = reference.clone();
+2 -2
View File
@@ -144,8 +144,8 @@ classes of similar sensor chromaticity (near-neutral and eight hue sectors), wei
that renders some hues brighter than others would otherwise read as vignetting where those hues gather toward the
corners. A CR3 proxy moved to its JPEG's framing gets the gain of the position each pixel shows, and a DNG's tone fit
(`fit_dng_tone`) takes a database profile in the measured share too. The whole correction is kept when nothing can
be measured: proxies of different sizes, fewer than 256 usable pixels (clipped, black and non-finite ones are left
out, as are chromaticity classes under 32 pixels), a lens-warped sensor proxy (the gain would no longer be at each
be measured: proxies of different sizes, fewer than 256 usable pixels (pixels clipped on the sensor or in the camera
JPEG, black and non-finite ones are left out, as are chromaticity classes under 32 pixels), a lens-warped sensor proxy (the gain would no longer be at each
pixel's source position); shares that rank alike keep the larger one. Within a class the camera's rendering is taken as alike, so two
saturations of one hue that it renders differently, one gathered toward the corners, can still read as vignetting.
With the whole profile, an ILCE-7M3 frame at f/2 with an FE 28mm F2 (lensfun: corners at 16 % of the centre) fitted