TensorImage is the wrapper class for Image object. When using image processing utils in TFLite.support library, it's common to convert image objects in variant types to TensorImage at first.
At present, only RGB images are supported, and the A channel is always ignored.
Details of data storage: a TensorImage
object may have 2 potential sources of truth: a
Bitmap
or a TensorBuffer
. TensorImage
maintains the
state and only converts one to the other when needed. A typical use case of TensorImage
is to first load a Bitmap
image, then process it using ImageProcessor
, and finally get the underlying ByteBuffer
of the TensorBuffer
and feed it into the TFLite interpreter.
IMPORTANT: to achieve the best performance, TensorImage
avoids copying data whenever
it's possible. Therefore, it doesn't own its data. Callers should not modify data objects those
are passed to load(Bitmap)
or load(TensorBuffer, ColorSpaceType)
.
IMPORTANT: all methods are not proved thread-safe.
Public Constructors
TensorImage()
Initializes a
TensorImage object. |
|
Public Methods
static TensorImage |
createFrom(TensorImage src, DataType dataType)
Creates a deep-copy of a given
TensorImage with the desired data type. |
static TensorImage |
fromBitmap(Bitmap bitmap)
|
Bitmap |
getBitmap()
Returns a
Bitmap representation of this TensorImage . |
ByteBuffer |
getBuffer()
Returns a
ByteBuffer representation of this TensorImage with the expected data
type. |
ColorSpaceType |