process

package
v0.0.0-...-be89aad Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package process implements image pre-processing and model-output post-processing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ImageToHWC

func ImageToHWC(img image.Image, colorMode config.ImageColorMode) []byte

ImageToHWC converts an image into a flat []byte in (H, W, C) order.

func ImagesToBatch

func ImagesToBatch(imgs []image.Image, cfg *config.PlateConfig) []byte

ImagesToBatch builds the model-ready uint8 tensor (N, H, W, C) from a batch of images.

Each image must already have the correct (H, W) dimensions.

func ReadAndResizePlateImage

func ReadAndResizePlateImage(path string, cfg *config.PlateConfig) (image.Image, error)

ReadAndResizePlateImage is a convenience wrapper: read an image from disk and resize it.

func ReadPlateImage

func ReadPlateImage(path string, colorMode config.ImageColorMode) (image.Image, error)

ReadPlateImage reads an image from disk in the colour mode specified by the config.

The returned image's colour space matches the mode:

  • Grayscale → *image.Gray
  • Rgb → *image.NRGBA with an opaque alpha channel

func ResizeImage

func ResizeImage(
	img image.Image,
	targetH, targetW int,
	colorMode config.ImageColorMode,
	keepAspectRatio bool,
	interp config.ImageInterpolation,
	paddingColor config.PaddingColor,
) (image.Image, error)

ResizeImage resizes an image to (targetW, targetH), honouring the config options.

When keepAspectRatio is true the image is letter-boxed with paddingColor. The output always has the colour space implied by colorMode.

func ToGray

func ToGray(img image.Image) *image.Gray

ToGray converts any image into an *image.Gray, matching `DynamicImage::to_luma8`.

An image that is already a tightly packed, origin-anchored *image.Gray is returned as-is rather than copied, so callers must not mutate the result in place.

func ToRGB

func ToRGB(img image.Image) *image.NRGBA

ToRGB converts any image into an *image.NRGBA with an opaque alpha channel, matching `DynamicImage::to_rgb8` (alpha is dropped, never blended).

Types

type PlatePrediction

type PlatePrediction struct {
	// Plate is the decoded license-plate string.
	Plate string
	// CharProbs holds the per-character confidence scores (nil unless returnConfidence).
	CharProbs []float32
	// Region is the predicted region / country label (nil when the model has no region head).
	Region *string
	// RegionProb is the probability of the predicted region (set together with Region when
	// returnConfidence is true).
	RegionProb *float32
}

PlatePrediction is the per-image plate prediction returned by the recognizer.

func PostprocessOutput

func PostprocessOutput(
	modelOutput []float32,
	n int,
	maxPlateSlots int,
	alphabet string,
	padChar rune,
	removePadChar bool,
	returnConfidence bool,
	regionOutput []float32,
	regionLabels []string,
) ([]PlatePrediction, error)

PostprocessOutput decodes the raw plate-head output tensor into PlatePrediction values.

Parameters:

  • modelOutput – flat float32 slice of shape (N * maxPlateSlots * vocabSize).
  • n – batch size.
  • maxPlateSlots – number of character positions.
  • alphabet – the model's character set.
  • padChar – padding character to strip from the right.
  • removePadChar – whether to strip trailing padChar.
  • returnConfidence– include per-character probabilities.
  • regionOutput – optional flat float32 slice (N * numRegions) (already softmaxed).
  • regionLabels – label list for the region head.

func (*PlatePrediction) AvgCharConfidence

func (p *PlatePrediction) AvgCharConfidence() float32

AvgCharConfidence returns the average character confidence, or 0.0 when confidence scores were not requested.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL