Skip to content
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

[Bug report] Subject segmentation returning mask of different size than image #913

Open
tomasbecket opened this issue Jan 30, 2025 · 2 comments
Assignees

Comments

@tomasbecket
Copy link

Describe the bug
For certain input image sizes the subject segmentation routine (16.0.0-beta1) returns mask buffer of a different size (a few pixels bigger in both dimensions), other image sizes work fine.

To Reproduce
The following code snippet and below some sample log outputs:

private val segmenter = SubjectSegmentation.getClient(SubjectSegmenterOptions.Builder()
    .enableForegroundConfidenceMask()
    .build())
suspend fun getMask(image: InputImage): Bitmap? {
    val result = segmenter.process(image).await()
    val buffer = result.foregroundConfidenceMask ?: return null
    Log.d(TAG, "Image size: ${image.width}x${image.height}=${image.width * image.height} Mask buffer size: ${buffer.position()} ${buffer.remaining()}")
    ...
}
// Image size: 320x240=76800 Mask buffer size: 0 79704
// 79704 = 324 x 246 WHY?!?!?!
// Image size: 1280x960=1228800 Mask buffer size: 0 1273654
// 1273654 = 1297 x 982 WHY?!?!?!
// Image size: 385x512=197120 Mask buffer size: 0 197120
// The above log is as expected

Expected behavior
As the documentation states (https://developers.google.com/ml-kit/vision/subject-segmentation): the foreground mask and foreground bitmap are the same size as the input image

SDK Info:
play-services-mlkit-subject-segmentation:16.0.0-beta1

Smartphone:
Pixel 8 (Android SDK 35)

@ai-plays ai-plays assigned ai-plays and SilverDestiny and unassigned ai-plays Feb 7, 2025
@SilverDestiny
Copy link
Collaborator

Could you provide the original problematic images so that I can try them out on my side? Thanks!

@tomasbecket
Copy link
Author

Thanks for coming back to me, attached is the image (creating InputImage with rotation of 90 degrees), also attaching the mask buffer that we've gotten from the subject segmenter.

Image
sample_1739265532691.bin.zip

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

No branches or pull requests

3 participants