Repository navigation
fix(crop): keep the whole picture on high-key frames - #1613
Draft
kurtwindisch wants to merge 2 commits into
Draft
kurtwindisch wants to merge 2 commits into
kurtwindisch wants to merge 2 commits into
Conversation
Auto Crop kept a fragment of the picture on some film scanner frames. Thin areas of a negative are as bright as the clear rebate, and two stages read that brightness as the end of the film or of the picture. A film box with two supported sides now reaches within 5% of the frame at its other sides. Film that runs off the scan does. A box that stops further in ended where a threshold mask ran out on picture content. A tier occupancy run now counts only when clear rebate lies past each end. A high-key picture dips under the run threshold mid-frame, and the edge walk reads those frames correctly. On 678 frames from a real library, 17 crops changed. Of 13 frames with a hand-drawn crop, 12 moved to it: the worst edge error fell from 61% of the frame to under 1%, and all 12 ended within 4.5%. One moved 0.1% and stays about 11% off. The other 4 hold a saved auto crop. No crop changed on the 139 1:1 frames. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kurtwindisch
force-pushed
the
fix/autocrop-high-key
branch
from
November 5, 2026 19:27
7894a20 to
8e209c5
Compare
The rebate check averaged occupancy past a run, so two good results were refused: a tilted edge spreads across lines, and a narrow frame gap leads into the next picture. A 2 degree tilt kept rebate in the crop, and a 10 px gap moved a 3:2 crop toward the next frame. The check now takes the clearest line within 3% of the side. On two real high-key frames, every line past a false end held at least 0.43 occupancy, and the true edge reached 0.005, so the 0.25 limit stays. The crops of all 678 frames in the regression set match the check this replaces. The film box rule now counts supported sides directly. Docs name the rule as fewer than three sides, and say that a picture area as bright as the rebate still reads as rebate. BOUNDS_VERSION and THUMBNAIL_RENDER_VERSION stay as they are. Saved crops and meter rects are frozen, and neither bump resets them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Auto Crop kept only a fragment of the picture on some film scanner frames. All the affected frames here are Coolscan B&W scans. Thin areas of a negative are as bright as the clear rebate, and two stages read that brightness as the end of the film or of the picture. Each failure has its own fix.
MAX_UNSUPPORTED_INSET,select_consensus). The surround check did not catch this, because a bright part of the picture passes as bed.TIER_MIN_KEEP. Each end of the run inside the box now needs a clear line within 3% of the side (run_ends_at_rebate). Otherwise the tiers abstain, and the edge walk reads these frames correctly. The check reads the clearest line, not the mean, so a tilted edge or a narrow frame gap still passes. A picture area as bright as the rebate reads as rebate, so this check does not catch that case.Crop All Frames also benefits. It placed the film-box failure wrongly before this change.
Results
Checked on 678 real frames from one library (Coolscan TIFFs and camera scans in CR3, DNG, RAF and ARW). 17 crops changed.
Every frame the tier stage resolved in this set was one of its failures, so the tier stage now resolves none of them. The rule for two-sided boxes has a clear gap in the data: unsupported sides sat within about 2% of the frame edge or deeper than 6.7%.
Square film in a 3:2 scan is not affected: no crop or film box changed on the 139 frames set to 1:1, whose wide margins are supported sides.
Saved frames
BOUNDS_VERSIONandTHUMBNAIL_RENDER_VERSIONare not bumped, as a deliberate choice. Saved crops and meter rects are frozen, and neither bump resets them, so a bump would re-meter or re-render every frame with no gain. New detections, a frame's meter rect included, use the new code.Open questions
make testcan segfault intests/test_key_hold.py. This is not from this PR: it happens onmain, and Segfault in test_key_hold: CanvasHud timer lambda runs after the collector clears it #1614 has the cause and its own fix.Test plan
uv run pytest tests(10671 passed), thenpytest tests --cov=negpy(same count) on the first commit, before the rebase. On the current branch, the crop, meter and skew test files passmake rust,make lint,make typepasstest_consensus_refuses_a_two_sided_box_that_stops_short_of_the_frame,test_tier_refinement_refuses_a_run_that_ends_inside_the_picture🤖 Generated with Claude Code