# SegmentationMask

public class **SegmentationMask** extends [Object](https://developer.android.com/reference/java/lang/Object.html)  
Result of `https://developers.google.com/android/reference/com/google/mlkit/vision/segmentation/Segmentation`.

### Public Method Summary

|---|---|
| [ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html) | [getBuffer](https://developers.google.com/android/reference/com/google/mlkit/vision/segmentation/SegmentationMask#getBuffer())() Returns a mask that indicates the foreground and background segmentation. |
| int | [getHeight](https://developers.google.com/android/reference/com/google/mlkit/vision/segmentation/SegmentationMask#getHeight())() Returns the height of the mask. |
| int | [getWidth](https://developers.google.com/android/reference/com/google/mlkit/vision/segmentation/SegmentationMask#getWidth())() Returns the width of the mask. |

### Inherited Method Summary

From class java.lang.Object

|---|---|
| [Object](https://developer.android.com/reference/java/lang/Object.html) | clone() |
| boolean | equals([Object](https://developer.android.com/reference/java/lang/Object.html) arg0) |
| void | finalize() |
| final [Class](https://developer.android.com/reference/java/lang/Class.html)\<?\> | getClass() |
| int | hashCode() |
| final void | notify() |
| final void | notifyAll() |
| [String](https://developer.android.com/reference/java/lang/String.html) | toString() |
| final void | wait(long arg0, int arg1) |
| final void | wait(long arg0) |
| final void | wait() |

## Public Methods

#### public [ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html)
**getBuffer** ()

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 `https://developer.android.com/reference/java/nio/ByteOrder.html#nativeOrder()`.

It relies on Garbage Collector to release the memory used by this buffer when it is
no longer referenced.

#### public int **getHeight** ()

Returns the height of the mask.

Without enabling raw size mask, this is the same as the height of the `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage`.
Check `https://developers.google.com/android/reference/com/google/mlkit/vision/segmentation/selfie/SelfieSegmenterOptions.Builder#enableRawSizeMask()` for details.

#### public int **getWidth** ()

Returns the width of the mask.

Without enabling raw size mask, this is the same as the width of the `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage`.
Check `https://developers.google.com/android/reference/com/google/mlkit/vision/segmentation/selfie/SelfieSegmenterOptions.Builder#enableRawSizeMask()` for details.