Skip to content

fix(cutout): read Vision's mask in its own pixel format - #79

Merged
Mxo01 merged 1 commit into
mainfrom
fix/78-restore-cutout
Nov 18, 2026
Merged

Mxo01 merged 1 commit into
mainfrom
fix/78-restore-cutout

Conversation

@Mxo01

@Mxo01 Mxo01 commented Nov 18, 2026

Copy link
Copy Markdown
Owner

What

After the matte change, a dark garment came out as a faint ghost and the classifier was fed that ghost. Vision's scaled foreground mask is a 32-bit float buffer, but the reader copied one UInt8 per pixel — the low byte of 1.0 is 0 — so the matte emptied without anything failing.

CutoutMatte now reads the buffer by its own CVPixelBufferGetPixelFormatType (OneComponent8, OneComponent32Float, 32BGRA alpha at byte 3, 32ARGB alpha at byte 0), honours the buffer's real bytesPerRow, clamps float samples to 0...1, reads non-finite samples as transparent, and refuses a format it does not know. GarmentSegmenter keeps only the Vision call and delegates; a matte that feathers away to nothing now fails as subject_not_found instead of handing an empty frame to review.

The review preview draws the cut-out on a mid-tone checkerboard instead of the near-black stage, so a black garment and a white one both read in dark mode; the original photo keeps the existing stage, and the "Background removed" badge stays tied to the cut-out.

Verification

  • Unit suite green: 341 tests, 51 suites; coverage gate 100% on CutoutMatte.swift (235/235) with the other three touched files allowlisted; Dynamic Type check clean.
  • Mask reader tests run on synthetic CVPixelBuffers: all four formats, padded 64-byte strides, clamping, NaN/±inf, an unsupported 24RGB refusal, and the regression proven red against the old one-byte read before being restored.
  • Review preview captured in dark mode for a dark hoodie and a white tee on the checkerboard, and for the original photo on the stage; screenshots reviewed.
  • The simulator cannot run Vision's foreground segmentation (Failed to create espresso context), so the end-to-end photo path is verified on device by the owner; the Debug build is installed on iMox from main after this merge.

Closes #78

@Mxo01
Mxo01 merged commit 4a7bc2a into main Nov 18, 2026
3 checks passed
@Mxo01
Mxo01 deleted the fix/78-restore-cutout branch November 18, 2026 17:42
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.

Restore the garment cut-out after the matte change

1 participant