Documentation
¶
Overview ¶
Mean is a simple color quantizer. The algorithm successively divides the color space much like a median cut algorithm, but a mean statistic is used rather than a median. In another simplification, there is no priority queue to order color blocks; linear search is used instead.
An added sopphistication though, is that division proceeds in two stages, with somewhat different criteria used for the earlier cuts than for the later cuts.
Motivation for using the mean is the observation that in a two stage algorithm, cuts are offset from the computed average so having the logically "correct" value of the median must not be that important. Motivation for the linear search is that the number of blocks to search is limited to the target number of colors in the palette, which is small and typically limited to 256. If n is 256, O(log n) and O(n) both become O(1).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Quantizer ¶
type Quantizer int
Quantizer methods implement mean cut color quantization.
The value is the target number of colors. Methods do not require pointer receivers, simply construct Quantizer objects with a type conversion.
The type satisfies both quant.Quantizer and draw.Quantizer interfaces.
func (Quantizer) Palette ¶
Palette performs color quantization and returns a quant.Palette object.
Returned is a palette with no more than q colors. Q may be > 256.
func (Quantizer) Paletted ¶
Paletted performs color quantization and returns a paletted image.
Returned is a new image.Paletted with no more than q colors. Note though that image.Paletted is limited to 256 colors.
func (Quantizer) Quantize ¶
Quantize performs color quantization and returns a color.Palette.
Following the behavior documented with the draw.Quantizer interface, "Quantize appends up to cap(p) - len(p) colors to p and returns the updated palette...." This method does not limit the number of colors to 256. Cap(p) or the quantity cap(p) - len(p) may be > 256. Also for this method the value of the Quantizer object is ignored.