quantizer

package
v0.2.0-beta Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxIterations       int     = 10
	MinMovementDistance float64 = 3.0
)

Variables

This section is empty.

Functions

func QuantizeWu

func QuantizeWu(input pixels, maxColor int) pixels

QuantizeWu is an image quantizer that divides the image's pixels into clusters by recursively cutting an RGB cube, based on the weight of pixels in each area of the cube.

The algorithm was described by Xiaolin Wu in Graphic Gems II, published in 1991.

func QuantizeWuContext

func QuantizeWuContext(
	ctx context.Context,
	input pixels,
	maxColor int,
) (pixels, error)

QuantizeWuContext is QuantizeWu with context.Context support.

func QuantizeWuWithContext deprecated

func QuantizeWuWithContext(
	ctx context.Context,
	input pixels,
	maxColor int,
) (pixels, error)

QuantizeWuWithContext is QuantizeWu with context.Context support.

Deprecated: Use QuantizeWuContext

Types

type QuantizedMap

type QuantizedMap = map[color.ARGB]int

func QuantizeCelebi

func QuantizeCelebi(input pixels, maxColor int) QuantizedMap

QuantizeCelebi is an image quantizer that improves on the quality of a standard K-Means algorithm by setting the K-Means initial state to the output of a Wu quantizer, instead of random centroids. Improves on speed by several optimizations, as implemented in Wsmeans, or Weighted Square Means, K-Means with those optimizations.

This algorithm was designed by M. Emre Celebi, and was found in their 2011 paper, Improving the Performance of K-Means for Color Quantization. https://arxiv.org/abs/1101.0395

func QuantizeCelebiContext

func QuantizeCelebiContext(ctx context.Context, input pixels, maxColor int) (QuantizedMap, error)

QuantizeCelebiContext is QuantizeCelebi with context.Context support. Returns ctx.Err() if context is Done.

func QuantizeCelebiWithContext deprecated

func QuantizeCelebiWithContext(ctx context.Context, input pixels, maxColor int) (QuantizedMap, error)

QuantizeCelebiWithContext is QuantizeCelebi with context.Context support.

Deprecated: Use QuantizeCelebiContext

func QuantizeMap

func QuantizeMap(input pixels) QuantizedMap

QuantizeMap takes a slice of []color.Color and returns Quantized

func QuantizeWsMeans

func QuantizeWsMeans(
	input pixels,
	startingClusters []color.Lab,
	maxColors int,
) QuantizedMap

QuantizeWsMeans is an image quantizer that improves on the speed of a standard K-Means algorithm by implementing several optimizations, including deduping identical pixels and a triangle inequality rule that reduces the number of comparisons needed to identify which cluster a point should be moved to.

Wsmeans stands for Weighted Square Means.

This algorithm was designed by M. Emre Celebi, and was found in their 2011 paper, Improving the Performance of K-Means for Color Quantization. https://arxiv.org/abs/1101.0395

func QuantizeWsMeansContext

func QuantizeWsMeansContext(
	ctx context.Context,
	input pixels,
	startingClusters []color.Lab,
	maxColors int,
) (QuantizedMap, error)

QuantizeWsMeansContext is QuantizeWsMeans with context.Context support.

func QuantizeWsMeansWithContext deprecated

func QuantizeWsMeansWithContext(
	ctx context.Context,
	input pixels,
	startingClusters []color.Lab,
	maxColors int,
) (QuantizedMap, error)

QuantizeWsMeansWithContext is QuantizeWsMeans with context.Context support.

Deprecated: Use QuantizeWsWithContext

Jump to

Keyboard shortcuts

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