quantizer

package
v1.1.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func QuantizeWu

func QuantizeWu(input []color.ARGB, maxColor int) []color.ARGB

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 []color.ARGB,
	maxColor int,
) ([]color.ARGB, error)

QuantizeWuContext is QuantizeWu with context.Context support.

Types

type QuantizedMap

type QuantizedMap = map[color.ARGB]int

QuantizedMap is a map where ARGB is key and their frequencies as int

func QuantizeCelebi

func QuantizeCelebi(input []color.ARGB, 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 []color.ARGB,
	maxColor int,
) (QuantizedMap, error)

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

func QuantizeMap

func QuantizeMap(input []color.ARGB) QuantizedMap

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

func QuantizeWsMeans

func QuantizeWsMeans(
	input []color.ARGB,
	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 []color.ARGB,
	startingClusters []color.Lab,
	maxColors int,
) (QuantizedMap, error)

QuantizeWsMeansContext is QuantizeWsMeans with context.Context support.

Jump to

Keyboard shortcuts

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