Skip to content

Preserve fine foreground edges in App Bokeh - #340

Merged
TTolsun merged 1 commit into
mainfrom
codex/bokeh-edges
Oct 24, 2026
Merged

TTolsun merged 1 commit into
mainfrom
codex/bokeh-edges

Conversation

@TTolsun

@TTolsun TTolsun commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

문제와 변경

App Bokeh의 256×256 깊이 맵에서 놓친 가는 잎 끝이 배경으로 분류돼 함께 흐려지는 문제를 줄입니다. 처리용 원본의 밝기로 guided filter를 적용해 흐림 가중치를 보정하고, 같은 가중치를 배경 색 표본과 최종 합성에 사용합니다. 기존에 보호하던 전경에 흐림을 추가하지 않습니다.

저장 메타데이터에 renderer=guided_luma_mask_v1을 추가했습니다. 깊이 PNG는 기존 모델 출력이며 합성 마스크와 구분합니다. 처리 계약·검증 기록·구조 문서 및 생성 사이트를 함께 갱신했습니다.

리뷰와 검증

  • 코드 리뷰: 가중치 범위, 영상 경계와 폭/높이 1, 전경 보존, 배경 무늬 유지, worker 처리 및 저장 계약을 검토했습니다. 머지를 막는 결함을 발견하지 못했습니다.
  • JVM 테스트 919개, lintDebug, 앱 및 기기 검사 APK 빌드를 통과했습니다.
  • 문서 최신성·생성물 검사 6단계와 문서 회귀 검사 37개를 통과했습니다.
  • SM-S936N, 직접 조회한 Android 17/API 37에서 같은 원본·중심 초점·강도 100으로 전후를 비교했습니다. 고정 잎 영역의 원본 대비 밝기 평균 절대 오차가 32.81 → 23.11(약 29.6% 감소)로 줄었고 먼 배경의 흐림은 유지됐습니다. 이 사진의 국소 비교값이며 일반 품질 점수가 아닙니다.
  • 실기기 편집기에서 Original/Depth 전환, 강도 0/50/100, 저장·닫기를 통과했습니다. 저장 JPEG와 비교 결과의 해시가 같고 원본 JPEG 해시는 보존됐습니다.
  • UI 배치 변경은 없습니다. 개인 촬영 사진과 비교 화면은 기존 약속대로 로컬 검증 자료로만 보관하며 PR에 게시하지 않습니다.

남은 한계

밝기가 비슷하거나 깊이 모델이 넓게 놓친 가는 구조물은 일부 흐려질 수 있고 경계 주변 배경 무늬가 더 선명해질 수 있습니다. 한 기기의 역광 사물 사진으로 확인했으며 다른 기기나 머리카락 품질을 보장하지 않습니다. 관찰된 강도 50/100 렌더 시간은 2264/1776 ms였고, 처리용 원본의 최대 긴 변은 1600픽셀입니다.

상세 검증: docs/validation/app-bokeh.md의 가는 잎 경계 보정 재검증.

Summary by Sourcery

Preserve fine App Bokeh foreground edges while maintaining background blur and clarifying the rendering output contract.

New Features:

  • Improve App Bokeh rendering to preserve fine foreground structures by refining blur weights against source-image luminance.
  • Record the Bokeh renderer version in output metadata while keeping depth PNGs as the original model output.

Bug Fixes:

  • Reduce unintended blur on thin foreground edges while preserving blur in distant backgrounds and avoiding added blur to already protected foreground regions.

Documentation:

  • Update App Bokeh architecture, design, validation, and generated documentation to describe the luminance-guided mask, output metadata, limitations, and verification results.

Tests:

  • Add coverage for thin foreground structures in both contrast directions, textured backgrounds, protected foreground pixels, uniform masks, and narrow or flat images.
  • Expand device checks to cover blur strengths 0, 50, and 100, saving, and result confirmation.

@sourcery-ai

sourcery-ai Bot commented Oct 24, 2026

Copy link
Copy Markdown

Sorry @TTolsun, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 days and 19 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

App Bokeh now refines coarse depth blur weights with a full-resolution luminance-guided filter, reuses the bounded mask for background sampling and compositing, preserves the original model depth output with explicit renderer metadata, and adds focused JVM/device validation plus updated architecture and validation documentation.

Sequence diagram for luminance-guided App Bokeh rendering

sequenceDiagram
    participant AppBokehProcessor
    participant RelativeDepth
    participant BokehMask
    participant DepthBokeh
    participant MediaLibrary

    AppBokehProcessor->>RelativeDepth: infer relative depth
    RelativeDepth-->>AppBokehProcessor: model depth
    AppBokehProcessor->>DepthBokeh: render(pixels, depth, focusX, focusY, strength)
    DepthBokeh->>BokehMask: refine(pixels, width, height, coarseWeights)
    BokehMask-->>DepthBokeh: bounded luminance-guided weights
    DepthBokeh->>DepthBokeh: blur(weights, width, height, radius)
    DepthBokeh-->>AppBokehProcessor: bokeh JPEG pixels
    AppBokehProcessor->>MediaLibrary: save JPEG, model depth PNG, renderer metadata
Loading

Flow diagram for shared App Bokeh blur mask

flowchart LR
    Source["Processing source RGB"] --> Luma["Full-resolution luminance"]
    Depth["256×256 model relative depth"] --> Coarse["Coarse blur weights"]
    Luma --> BokehMask["BokehMask.refine"]
    Coarse --> BokehMask
    BokehMask --> Mask["Bounded refined weights"]
    Mask --> Sampling["Background color sampling"]
    Mask --> Composite["Final blur compositing"]
    Depth --> DepthPNG["Original model depth PNG"]
    Metadata["renderer=guided_luma_mask_v1"] --> Output["Saved App Bokeh outputs"]
    Sampling --> Output
    Composite --> Output
    DepthPNG --> Output
Loading

File-Level Changes

Change Details Files
Adds a luminance-guided refinement stage to preserve thin foreground edges while preventing additional blur on already-protected foreground.
  • Computes full-resolution luminance guidance and local linear coefficients with separable, clipped box means.
  • Clamps refined weights to the coarse depth weights before blur compositing.
  • Uses the refined weights for both background color sampling and final compositing.
  • Adds coverage for bright/dark thin subjects, textured backgrounds, protected pixels, uniform masks, flat guidance, and 1-pixel dimensions.
app/src/main/java/dev/halcamera/camera/BokehMask.kt
app/src/main/java/dev/halcamera/camera/RelativeDepth.kt
app/src/test/java/dev/halcamera/camera/BokehMaskTest.kt
Extends App Bokeh output metadata and validation to distinguish the guided renderer from the original model depth output.
  • Records renderer=guided_luma_mask_v1 while retaining the unmodified relative-depth PNG.
  • Captures exact depth floats and per-strength render timings in device validation artifacts.
  • Expands UI checks across strength 0/50/100 and verifies save completion and output contracts.
app/src/main/java/dev/halcamera/camera/AppBokehProcessor.kt
app/src/androidTest/java/dev/halcamera/camera/AppBokehChecks.kt
Documents the new mask-processing contract, implementation limits, and device-level revalidation.
  • Updates data flow, architecture, design, and generated guide content with the guided-filter behavior and renderer contract.
  • Records the Android 17/API 37 edge-preservation comparison, local image metrics, timing observations, and known limitations.
  • Refreshes documentation evidence, bindings, manifests, and generated state.
.omm/data-flow/description.md
.omm/overall-architecture/camera-engines/app-bokeh/description.md
docs/design/APP-BOKEH.md
docs/validation/app-bokeh.md
docs/architecture.html
guide/_bindings.yaml
guide/_content/architecture/module-roles.md
guide/_content/architecture/runtime-flow.md
guide/_reference/engine.md
guide/_reference/evidence.md
guide/_reference/troubleshooting.md
guide/architecture.md
docs/.site-manifest.json
tools/docgen/state/evidence.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@TTolsun
TTolsun merged commit bdb73f9 into main Oct 24, 2026
7 checks passed
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.

1 participant