8000 Optimize selfie segmentation mask for green screen by temcguir · Pull Request #1 · donovanfm/socialite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Optimize selfie segmentation mask for green screen #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

temcguir
Copy link
@temcguir temcguir commented May 9, 2025
  • Uses the raw size mask from selfie segmentation. This is generally much smaller than the image, and it can be scaled when drawn.

  • Stores the mask in an A8 image. This uses less memory and can be drawn with a ColorMatrixColorFilter to restore it to RGBA

  • Uses line buffer to read from the selfie segmentation mask buffer to keep memory localized while performing conversion from floats to bytes.

  • Reduces allocations by reusing buffers used for mask conversion

These optimizations reduced the selfie segmentation mask logic from ~24ms to < 8ms on a Pixel 9. Further optimizations are possible, but will require more drastic changes to the drawing logic.

 - Uses the raw size mask from selfie segmentation. This is
   generally much smaller than the image, and it can be
   scaled when drawn.

 - Stores the mask in an A8 image. This uses less memory and
   can be drawn with a ColorMatrixColorFilter to restore it
   to RGBA

 - Uses line buffer to read from the selfie segmentation mask
   buffer to keep memory localized while performing conversion
   from floats to bytes.

 - Reduces allocations by reusing buffers used for mask conversion

These optimizations reduced the selfie segmentation mask logic from
~24ms to < 8ms on a Pixel 9. Further optimizations are possible, but
will require more drastic changes to the drawing logic.
Copy link
Owner
@donovanfm donovanfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look great! And it feels very snappy on my Pixel 9 Pro XL too. Thanks!

@donovanfm donovanfm merged commit 8af3561 into donovanfm:green-screen May 9, 2025
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.

2 participants
0