Repository navigation
PEF: masked rows and columns at the black level are trimmed without crop tags - #1288
Conversation
…e interior, so dark real content stays (storytold#1271)
|
I measured this branch (a9812d0) on every CC0 PEF the all-makes sweep used: 38 files from 30 bodies. The renders are full size, default settings, compared with
Gaps
Suggested fixKeep your absolute tolerance, which rightly keeps the dark real content in your second test. Measure it over the outermost line's level when that line sits a little above black. Count saturated outer lines when dark ones follow, and keep the whole area when the interior itself is within the tolerance. A sketch, replacing let (base, tol) = match black {
Some(b) => (b, ((f64::from(white) - b) / 256.0).max(16.0)),
None => (0.0, interior * 0.05),
};
// a frame no brighter than masked lines (a lens-cap shot) has nothing to tell them from picture
if interior - base <= tol {
return Rect::new(0, 0, w, h);
}
let range = f64::from(white) - base;
// lines from one edge that hold no picture: within `tol` of the outermost line's level when that sits a
// little above black (K-70, K-1: 65 over BlackPoint), and saturated lines when dark ones follow (645Z)
let run = |at: &dyn Fn(usize) -> f64| {
let saturated = (0..64).take_while(|&k| at(k) - base >= range * 0.98).count();
let outer = at(saturated) - base;
let level = if outer > 0.0 && outer < range * 0.01 { outer } else { 0.0 };
match (saturated..64).take_while(|&k| at(k) - base < level + tol).count() {
0 => 0,
dark => saturated + dark,
}
};
let edges = |n: usize, mean: &dyn Fn(usize) -> f64| {
let lo = run(&|k| mean(k)).next_multiple_of(2);
let hi = n - run(&|k| mean(n - 1 - k));
(lo, (hi - lo) & !1)
};With this in place, both of your tests pass, and so do three more. One is a K-70 layout: masked lines at black + 65 and empty bottom rows, expected Not for this PR: on two of the six K-3 Mark III files (4677 and the Monochrome), up to 28 right columns and 14 bottom rows are neither picture nor black. They stay here and in any dark-line rule (edge ΔL* right -10.7, bottom -6.1 on 4677). A per-model crop to the camera frame, as #1053 does for Nikon, would cover them. |
…saturated lines outside masked ones, and keeps a lens-cap frame whole (storytold#1271) Masked lines are measured against the outermost line's level when it sits just above BlackPoint (K-70, K-1), saturated outer lines count when dark ones follow (645Z), and a frame whose interior is within the tolerance keeps its whole area. Line means read samples with get(). Render cache version 62: PEF frames change size.
…checklist and what's new (storytold#1271)
|
All five gaps are in two new commits:
KP, KF and K-3 Mark III come out at the same sizes as before. One case I can still see over-trimming: a PEF without area tags or a masked border, whose picture reaches the edge with a dark sky within 1% of the range. That level becomes the base, and up to 64 lines could go. None of your 38 files does it, so I left it. The K-3 Mark III per-model crop stays out, as you suggested. |
|
Thanks, @marcoarnulfo, that covers all five points from my review. Agreed on leaving the dark-sky edge case and the K-3 Mark III per-model crop for later. None of the 38 sample files hits the first one, and the second fits better with a per-body frame table like #1053's. |
|
Landed on main in #1431. Thank you, @marcoarnulfo! Generated by Claude Code |
… every menu and submenu Manual: start/layouts Refs storytold#1288 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #1271.
Without crop tags,
dark_trimmedcompared raw column means with 5% of the interior's raw mean, so masked columns sitting at the black level (BlackPoint 64/128/256 on these bodies) only counted as dark when the interior was more than 20 times brighter than black, and it never looked at rows. It now takes the maker-note BlackPoint (already read here) and treats a line as dark when its mean is at most 1/256 of the remaining range (at least 16 DN) above it, the same tolerancecr2::masked_columnsuses: masked lines sit at black plus noise, while dark real content such as a night sky is well above, whatever the interior's brightness. When the outermost line sits a little above BlackPoint (the K-70 and K-1 mask at 65 DN over it), the tolerance is measured from that line's level; saturated outer lines count when dark ones follow (the 645Z's 12 white columns outside its 46 masked ones); a frame whose interior is itself within the tolerance (a lens-cap shot) keeps its whole area. Rows get the same scan as columns, keeping even offsets so the CFA phase doesn't move. Files without BlackPoint keep the old 5% rule. Render cache version goes to 62, since these frames change size.Bodies covered: KP, KF, K-3 Mark III (and Monochrome), K-70, K-1, K-1 Mark II, K-S1, K-S2, 645Z. On the three files from the issue: KP 6032 x 4032, KF 6024 x 4024, K-3 Mark III 6264 x 4176 (24/16 columns, 34/14 rows). Docs: the PEF row of
docs/raw-parity.md, LR-IMP-CAMERA-COVERAGE indocs/parity-checklist.md,docs/whats-new.md.Validation:
masked_rows_and_columns_at_the_black_level_are_trimmed_without_crop_tags(BlackPoint 256, dim interior): fails on main (0,0 504x384, only the all-zero columns go), passes heredark_real_content_next_to_the_masked_border_is_kept(bright centre, content 100 DN over black inside the border): fails with a 5%-of-interior threshold (44,48 432x302), passes heremasked_lines_a_little_above_the_black_level_are_trimmed(K-70 layout, 320 x 288):56,28 264x248, was56,0 264x276saturated_lines_outside_masked_ones_are_trimmed(645Z layout): 58 right columns go, was nonea_saturated_edge_followed_by_picture_staysanda_frame_at_the_black_level_keeps_its_whole_area(the lens-cap one was64,64 192x160)cargo test -p lightcraft-raw --lib vendor::pef,cargo test -p lightcraft-raw --test vendor_robustcargo clippy -p lightcraft-raw --all-targets -- -D warnings,cargo fmt --all -- --check