Repository navigation
Issue #3272: AI masks are enlarged along the photo's edges, no outline under a raised Exposure - #3298
Conversation
…no outline under a raised Exposure An Object / Describe mask is stored as a model's logit grid (288² over the whole photo, ~20 px cells on a 24 MP export) and was enlarged by bilinear sampling alone, so its edge spilled 1–2 px onto the background; raising the mask's Exposure turned that strip into a bright outline in previews and exports (CPU and GPU: the GPU renderer evaluates these shapes with the same CPU `shape_alpha`). `sample_seg` now guided-filters the sampled logits by the photo's log luminance where the grid is coarser than the output: the fast (subsampled) guided filter, a window of 1.5 grid cells, so a preview and an export put the edge in the same place. Filtering logits, not coverage, lets the confident side win (the spill goes to ≈ 0, not to a mean of ≈ 0.1). Pixels whose window is all inside or all outside, and edges the photo has no contrast across, keep the plain sample exactly. Refine Edges still runs afterwards on the combined mask and finds the edges in place: no second halo, no tightening. One implementation: `guided_cross` (Refine Edges, Auto Mask) and the new `guided_cross_fast` share `guided_coeffs`; the subsampled form uses `local::guided_fast_step` and a box `resize`, like `local::guided_fast`. `guided_cross`'s output is unchanged. Existing AI masks become 1–2 px tighter at a subject's edges, on every process; their inside, outside and contrast-less edges are unchanged. This lands in place under the bug-fix rule of docs/process-versions.md (output that is in neither the photo nor the edit), noted there. Cost per AI selection (M2 Pro, 12 cores; one shape_alpha, before → after): 24 MP 25.7 → 48.2 ms, heap peak 96.5 → 108.8 MB; 60 MP 64.1 → 109.9 ms, 239.9 → 256.7 MB; 2.7 MP preview 3.1 → 10.6 ms, 11.2 → 26.5 MB. Tests (a dark disc on a light background, its mask on a 32² grid): ≈ 0 one and two px outside and ≈ 1 inside, all around (1 px outside was 0.66), bit-identical away from the edge; with Refine Edges 50 / 100 (was 0.29 outside) and the edge within 1 px of the unrefined one; the same edge position at 256, 512 and 1024 px; a Prompt mask's window matches the whole render. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Filter sampled segmentation logits crates/pipeline/src/masks.rs |
sample_seg now uses log luminance to guide filtering of sampled logits before converting them to coverage. The filtering path shares coefficient calculations with guided_cross. |
Validate and document mask edges crates/pipeline/src/masks/tests.rs, crates/pipeline/src/tests_window.rs, docs/ai-masks.md, docs/gaps.md, docs/parity-checklist.md, docs/process-versions.md |
Tests check mask edges across output sizes, after Refine Edges, and in mask-overlay cases. Documentation describes the edge behavior, reported processing costs, and revision history. |
Priority:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
storytold/lightcraft#3270— Its section on the prompt-mask outline describes the same edge-spill behavior addressed here; its other reported topics are outside this change.
Suggested reviewers: echelon, kovalskiguinther, emmertex
Merge Risk: 
Minimal · up to f14d1
-
No actionable issue remains from this review; the change is mergeable after normal checks.
Pre-merge checks: 
5
-
Full details: Title check
-
Explanation
The title names the issue number and the main behavior change: AI mask enlargement now follows photo edges, which removes the outline under raised Exposure. The changeset guide-filters sampled mask logits with the photo's log luminance in sample_seg, so the title matches the primary change. The title is long (94 characters, 16 words) and includes an issue reference, but it is specific and related to the code and docs changes.
Full details: Linked Issues check
-
Explanation
Issue
#3272requires reducing the outline caused by coarse AI-mask enlargement.sample_segnow guides sampled segmentation logits with photo log luminance when the grid is coarse.shape_alphastill applies Refine Edges after mask composition. Tests cover the outside spill, inside coverage, unchanged flat regions, Refine Edges, and consistent preview/export edge placement. The documented changes also identify#3272.
Full details: Out of Scope Changes check
-
Explanation
The code changes, regression tests, window-render test fixture, and AI-mask documentation support the
#3272fix. The process-version, parity, and gap notes record the same behavior. The reviewed evidence shows no unrelated implementation, dependency, build, or asset changes.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 90.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 10 functions across 3 files. (4 skipped: 4 unsupported.)
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
Adapted from upstream #3298: an Object / Describe mask is stored as a model's logit grid (288² over the whole photo, ~20 px cells on a 24 MP export) and was enlarged by bilinear sampling alone, so its edge spilled 1-2 px onto the background; a raised Exposure turned that strip into a bright outline, in previews and exports (the GPU renderer evaluates these shapes with the same CPU shape_alpha). sample_seg now guided-filters the sampled logits by the photo's log luminance where the grid is coarser than the output (the fast guided filter, a window of 1.5 grid cells). guided_cross and the new guided_cross_fast share guided_coeffs; guided_cross's output is unchanged. Chromaforge's People and Concept (remembered object) grids keep the plain enlargement: sample_seg takes the guide as an Option, and they pass None until the filter is checked on them. Lands in place as a bug fix (docs/process-versions.md); RENDER_CACHE_VERSION is already bumped on this branch. Measured here (release build, best of 5, load ~8; one sample_seg on a 288² grid, plain -> guided): 24 MP 13.2 -> 36.6 ms, 60 MP 32.0 -> 85.9 ms, 2.7 MP 1.9 -> 10.8 ms. On the tests' disc scene (32² grid, 512 px): 1 px outside the edge 0.658 -> 0.000, 2 px outside 0.430 -> 0.000, 1 px inside 0.831 -> 1.000. Adapted from upstream commit f14d166, with the doc-comment fix of 737c686; the tests move to masks.rs's inline tests. Sources: upstream #3298, commits f14d166 and 737c686; He, Sun and Tang, "Guided Image Filtering"; He and Sun, "Fast Guided Filter" (2015). Co-authored-by: Brain Wang <wm20062006@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #3272
Problem
An Object / Describe (AI) mask is stored as the model's logit grid: 288² over the whole photo, so ~20 px cells on a 24 MP export. It was enlarged to the output by bilinear sampling alone, without looking at the photo, so its 0.5 contour could sit up to a cell away from the subject's real edge and the mask spilled 1–2 px onto the background. Raising the mask's Exposure brightened that strip into a thin outline around the whole subject, in the preview and in exports (the reporter's rider on light asphalt). Refine Edges alone doesn't fix it: on the test scene it still left 0.29 one pixel outside the edge.
Change
crates/pipeline/src/masks.rs, insample_seg, the one path for these shapes. Preview, export, overlay and windowed renders all use it, and the GPU renderer evaluates these shapes with the same CPUshape_alpha, so CPU and GPU are both covered.var / (var + eps)edge term), keep the plain sample exactly, bit for bit. So texture inside a subject can't punch holes, and featureless areas aren't blurred.guided_cross(Refine Edges, Auto Mask) and the newguided_cross_fastshareguided_coeffs; the subsampled form useslocal::guided_fast_stepand a boxresize, likelocal::guided_fast.guided_cross's output is unchanged.local::guided_fastitself isn't touched (its maths feeds the frozen V2 tone base).docs/ai-masks.md(Edge section),docs/process-versions.md(bug-fix note), the LR-MASK-OBJECTS row indocs/parity-checklist.md, anddocs/gaps.md(gap 5 stays open).Not in this PR:
main(max difference 22 levels, 37 with this change): Refine Edges gets no padding around a window, so its filter sees only the window's pixels. That's a general Refine Edges limitation, so that case is left out of the window test.matte_alpha, e.g. iPhone ProRAW) are still enlarged bilinearly.How it was checked
crates/pipeline/src/masks/tests.rs):ai_masks_follow_the_photos_edge_when_enlarged: 1 px outside the edge was 0.66, now < 0.05; > 0.95 one and two px inside, all around the disc; identical to the plain sample away from the edge.refine_edges_on_an_enlarged_ai_mask_neither_halos_nor_tightens: Refine Edges 50 / 100 on top. No second halo, edge within 1 px of the unrefined one.enlarged_ai_masks_put_the_edge_in_the_same_place_at_any_size: the edge lands at the disc's edge at 256, 512 and 1024 px.crates/pipeline/src/tests_window.rs: a Prompt mask rendered in a window matches the whole render.cargo xtask ciwithCRAFT_FONTS_DIRset (macOS, stable 1.99.1): fmt passes; clippy stops only atmain's ownapps/lightcraft/src/native_menu.rs:492, fixed in MENU-BAR: merge the native menu's identical quit/about/settings branches (clippy::if_same_then_else) #3295. The remaining steps were run on their own and pass: heif (clippy and tests), the workspace tests (5075 passed, 0 failed), doctests, parity, layers, assets and wasm.Cost per AI selection (one
shape_alpha, M2 Pro, before → after, same build):Only reduced-size planes are added, no full-size ones. It runs only for components that hold a model grid. The +7.5 ms on a preview counts against the slider budget; caching mask results (#1147) would mostly remove it.
Merging
guided_crossto snap a new automatic Sky/Subject grid to the photo, but doesn't touch stored model masks; it may conflict mechanically inmasks.rs.docs/process-versions.md(output that is in neither the photo nor the edit, not a look anyone chose), noted there. Gating it behind a new process version would need plumbing throughshape_alphaand collide with the open V3 PRs (LRC-DEV-TONAL: consolidate tonal processing as V11 #3266, LR-BEHAV-RENDER-FIDELITY: process V3 Highlights, Shadows, Whites and Blacks (#523) #2313). Happy to gate it if you'd rather.guided_cross/local::guided_fast. No outside code.unsafe, build scripts, network access, spawned processes, deleted files, CI orxtaskgate changes: none.Checklist
unwrap/expect/panic!, no unchecked indexing (sizes checked,get)docs/parity-checklist.md(LR-MASK-OBJECTS) anddocs/gaps.mdare updated in the same commit🤖 Generated with Claude Code
Summary by CodeRabbit