RgbImage

class RgbImage(val width: Int, val height: Int, val data: ByteArray)

An immutable-by-convention, packed 8-bit RGB image (R,G,B,R,G,B,..., row-major, no row padding).

Every Faktel algorithm consumes this single type; platform frame formats (Android Bitmap/ImageProxy, iOS CVPixelBuffer/UIImage) are converted to it once at the edge of the pipeline.

Constructors

Link copied to clipboard
constructor(width: Int, height: Int, data: ByteArray)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
val height: Int
Link copied to clipboard
val width: Int

Functions

Link copied to clipboard
fun b(x: Int, y: Int): Int
Link copied to clipboard
fun RgbImage.blurScore(normalizedSize: Int = 256): Double

Focus score on a normalised copy whose longest side is normalizedSize, so results are comparable between a 4K photo and a 720p camera frame.

Link copied to clipboard
fun crop(region: Rect): RgbImage

Crops to region (clamped to the image bounds, coordinates truncated to whole pixels).

Link copied to clipboard

Mirrors the image left-to-right (typical for front-camera selfies).

Link copied to clipboard
fun g(x: Int, y: Int): Int
Link copied to clipboard
fun RgbImage.letterbox(size: Int, padValue: Int = 0): Letterbox

Resizes preserving aspect ratio to fit inside size x size, centring it on a canvas filled with padValue.

Link copied to clipboard
fun r(x: Int, y: Int): Int

Returns the red/green/blue value (0..255) at (x, y).

Link copied to clipboard
fun resize(newWidth: Int, newHeight: Int): RgbImage

Bilinear resize using half-pixel centres (the same convention as OpenCV INTER_LINEAR, no antialiasing).

Link copied to clipboard
fun rotate(degrees: Int): RgbImage

Rotates clockwise by degrees, which must be a multiple of 90. Use it to apply camera sensor rotation.

Link copied to clipboard
fun RgbImage.saturatedRatio(threshold: Int = 250): Double

Fraction (0.0..1.0) of pixels where all channels are at least threshold - i.e. blown-out highlights such as glare on a laminated card.

Link copied to clipboard

Luma (ITU-R BT.601) grayscale copy.

Link copied to clipboard
fun RgbImage.toTensor(order: ChannelOrder, mean: Float = 0.0f, scale: Float = 1.0f): Tensor

Packs the image into a [1, 3, height, width] float tensor: (value - mean) * scale per channel value.

Link copied to clipboard
fun RgbImage.warpPerspective(quad: Quad, outWidth: Int, outHeight: Int): RgbImage

Perspective-corrects the region bounded by quad into an upright outWidth x outHeight image (the top-left corner of quad becomes the output's top-left, and so on clockwise).

Link copied to clipboard
fun RgbImage.warpSimilarity(transform: SimilarityTransform, outWidth: Int, outHeight: Int): RgbImage

Applies transform (source -> output coordinates) and renders an outWidth x outHeight image.