SegmentationMask
Stay organized with collections
Save and categorize content based on your preferences.
Public Method Summary
ByteBuffer
|
getBuffer()
Returns a mask that indicates the foreground and background segmentation.
|
int |
|
int |
getWidth()
Returns the width of the mask.
|
Inherited Method Summary
From class java.lang.Object
Object
|
clone()
|
boolean |
|
void |
finalize()
|
final Class<?>
|
getClass()
|
int |
hashCode()
|
final void |
notify()
|
final void |
notifyAll()
|
String
|
toString()
|
final void |
wait(long arg0, int arg1)
|
final void |
wait(long arg0)
|
final void |
wait()
|
Public Methods
Returns a mask that indicates the foreground and background segmentation.
This mask’s dimensions could vary, depending on whether a raw size mask is requested
via options.
The value of each pixel of the mask is a float number within range [0f, 1f]. It
represents the confidence of the pixel being in the foreground. Specifically, 1.0 means
the highest confidence of being a foreground pixel, while 0.0 means the highest
confidence of being a background pixel.
The capacity of this mask ByteBuffer is maskWidth * maskHeight * 4, where 4 is the
byte size of a float number. You can iterate through the mask ByteBuffer as
follows:
for (int y = 0; y < maskHeight; y++) {
for (int x = 0; x < maskWidth; x++) {
// Gets the confidence of the (x,y) pixel in the mask being in the foreground.
float foregroundConfidence = mask.getFloat();
}
}
The byte order of this buffer is ByteOrder.nativeOrder()
.
It relies on Garbage Collector to release the memory used by this buffer when it is
no longer referenced.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eSegmentationMask\u003c/code\u003e provides a mask that differentiates foreground from background in an image, with each pixel's value indicating its confidence of being in the foreground.\u003c/p\u003e\n"],["\u003cp\u003eThe mask's dimensions (width and height) can be retrieved using \u003ccode\u003egetWidth()\u003c/code\u003e and \u003ccode\u003egetHeight()\u003c/code\u003e, and these might align with the input image's dimensions depending on configuration.\u003c/p\u003e\n"],["\u003cp\u003eThe mask data is accessible through a \u003ccode\u003eByteBuffer\u003c/code\u003e obtained via \u003ccode\u003egetBuffer()\u003c/code\u003e, allowing iteration to examine each pixel's foreground confidence.\u003c/p\u003e\n"],["\u003cp\u003ePixel confidence values range from 0.0 (highest background confidence) to 1.0 (highest foreground confidence), represented as floats in the \u003ccode\u003eByteBuffer\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["public class **SegmentationMask** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nResult of [Segmentation](/android/reference/com/google/mlkit/vision/segmentation/Segmentation). \n\nPublic Method Summary\n\n|--------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [ByteBuffer](//developer.android.com/reference/java/nio/ByteBuffer.html) | [getBuffer](/android/reference/com/google/mlkit/vision/segmentation/SegmentationMask#getBuffer())() Returns a mask that indicates the foreground and background segmentation. |\n| int | [getHeight](/android/reference/com/google/mlkit/vision/segmentation/SegmentationMask#getHeight())() Returns the height of the mask. |\n| int | [getWidth](/android/reference/com/google/mlkit/vision/segmentation/SegmentationMask#getWidth())() Returns the width of the mask. |\n\nInherited Method Summary \nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Methods \n\npublic [ByteBuffer](//developer.android.com/reference/java/nio/ByteBuffer.html)\n**getBuffer** () \nReturns a mask that indicates the foreground and background segmentation.\n\nThis mask's dimensions could vary, depending on whether a raw size mask is requested\nvia options.\n\nThe value of each pixel of the mask is a float number within range \\[0f, 1f\\]. It\nrepresents the confidence of the pixel being in the foreground. Specifically, 1.0 means\nthe highest confidence of being a foreground pixel, while 0.0 means the highest\nconfidence of being a background pixel.\n\nThe capacity of this mask ByteBuffer is maskWidth \\* maskHeight \\* 4, where 4 is the\nbyte size of a float number. You can iterate through the mask ByteBuffer as\nfollows: \n\n for (int y = 0; y \u003c maskHeight; y++) {\n for (int x = 0; x \u003c maskWidth; x++) {\n // Gets the confidence of the (x,y) pixel in the mask being in the foreground.\n float foregroundConfidence = mask.getFloat();\n }\n }\n\nThe byte order of this buffer is [ByteOrder.nativeOrder()](//developer.android.com/reference/java/nio/ByteOrder.html#nativeOrder()).\n\nIt relies on Garbage Collector to release the memory used by this buffer when it is\nno longer referenced. \n\npublic int **getHeight** () \nReturns the height of the mask.\n\nWithout enabling raw size mask, this is the same as the height of the [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage).\nCheck [SelfieSegmenterOptions.Builder.enableRawSizeMask()](/android/reference/com/google/mlkit/vision/segmentation/selfie/SelfieSegmenterOptions.Builder#enableRawSizeMask()) for details. \n\npublic int **getWidth** () \nReturns the width of the mask.\n\nWithout enabling raw size mask, this is the same as the width of the [InputImage](/android/reference/com/google/mlkit/vision/common/InputImage).\nCheck [SelfieSegmenterOptions.Builder.enableRawSizeMask()](/android/reference/com/google/mlkit/vision/segmentation/selfie/SelfieSegmenterOptions.Builder#enableRawSizeMask()) for details."]]