LiteRtImage

expect class LiteRtImage

Represents an image that can be preprocessed before being fed into a LiteRT model.

This class provides common image operations such as resizing and converting pixel data into a normalized FloatArray.

Platform-specific implementations are provided for each supported target.

Types

Link copied to clipboard
expect object Companion

Properties

Link copied to clipboard
expect val channels: Int

The number of color channels in the image (e.g., 3 for RGB, 4 for RGBA, 1 for Grayscale).

Link copied to clipboard
expect val height: Int

The height of the image in pixels.

Link copied to clipboard
expect val width: Int

The width of the image in pixels.

Functions

Link copied to clipboard
expect fun centerCrop(width: Int, height: Int): LiteRtImage

Returns a center-cropped copy of this image.

Link copied to clipboard
expect fun crop(x: Int, y: Int, width: Int, height: Int): LiteRtImage

Returns a cropped copy of this image.

Link copied to clipboard
expect fun flip(horizontal: Boolean, vertical: Boolean): LiteRtImage

Returns a flipped copy of this image.

Link copied to clipboard
expect fun resize(width: Int, height: Int): LiteRtImage

Returns a resized copy of this image.

Link copied to clipboard
expect fun rotate(degrees: Float): LiteRtImage

Returns a rotated copy of this image.

Link copied to clipboard

Converts the image into a boolean array.

Link copied to clipboard
expect fun toFloatArray(mean: Float = 0.0f, std: Float = 1.0f): FloatArray

Converts the image into a normalized float array.

Link copied to clipboard
expect fun toGrayscale(): LiteRtImage

Converts the image to grayscale.

Link copied to clipboard
expect fun toInt8Array(): ByteArray

Converts the image into a signed 8-bit integer array (ByteArray).

Link copied to clipboard
expect fun toIntArray(): IntArray

Converts the image into an integer array.

Link copied to clipboard
expect fun toLongArray(): LongArray

Converts the image into a long array.

Link copied to clipboard
expect fun toRgb(): LiteRtImage

Converts the image to RGB format (discarding alpha if present).

Link copied to clipboard
expect fun writeFloatBuffer(buffer: TFBuffer, mean: Float = 0.0f, std: Float = 1.0f)

Directly writes the image pixel data to a float TFBuffer with normalization.

Link copied to clipboard
expect fun writeInt8Buffer(buffer: TFBuffer)

Directly writes the image pixel data to a signed 8-bit integer io.github.kmplitert.core.TFBuffer.