Repository navigation
fix(cutout): read Vision's mask in its own pixel format - #79
Merged
Merged
Conversation
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.
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
UInt8per pixel — the low byte of1.0is0— so the matte emptied without anything failing.CutoutMattenow reads the buffer by its ownCVPixelBufferGetPixelFormatType(OneComponent8,OneComponent32Float,32BGRAalpha at byte 3,32ARGBalpha at byte 0), honours the buffer's realbytesPerRow, clamps float samples to 0...1, reads non-finite samples as transparent, and refuses a format it does not know.GarmentSegmenterkeeps only the Vision call and delegates; a matte that feathers away to nothing now fails assubject_not_foundinstead 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
CutoutMatte.swift(235/235) with the other three touched files allowlisted; Dynamic Type check clean.CVPixelBuffers: all four formats, padded 64-byte strides, clamping, NaN/±inf, an unsupported24RGBrefusal, and the regression proven red against the old one-byte read before being restored.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 frommainafter this merge.Closes #78