SegmentationMask

public class SegmentationMask extends Object

Result of Segmentation.

Public Method Summary

ByteBuffer
getBuffer()
Returns a mask that indicates the foreground and background segmentation.
int
getHeight()
Returns the height of the mask.
int
getWidth()
Returns the width of the mask.

Inherited Method Summary

Public Methods

public ByteBuffer 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 ByteOrder.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 InputImage. Check 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 InputImage. Check SelfieSegmenterOptions.Builder.enableRawSizeMask() for details.