Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/delthas/octreequant
A simple library for converting images to paletted images (color quantization) fast.
https://github.com/delthas/octreequant
Last synced: 2 days ago
JSON representation
A simple library for converting images to paletted images (color quantization) fast.
- Host: GitHub
- URL: https://github.com/delthas/octreequant
- Owner: delthas
- License: mit
- Created: 2024-07-05T22:34:01.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2024-07-24T15:23:56.000Z (4 months ago)
- Last Synced: 2024-07-24T17:55:31.586Z (4 months ago)
- Language: Go
- Size: 1.07 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# octreequant [![GoDoc](https://godocs.io/github.com/delthas/octreequant?status.svg)](https://godocs.io/github.com/delthas/octreequant)
A simple library for converting images to paletted images (color quantization) fast.
Quantizing an image takes a substantial amount of time, in the order of a second, so using an optimized algorithm/library matters. This library uses the fastest mainstream quantization algorithm.
Main quantization algorithms:
- Slowest: Generating a palette, then "**brute-forcing**" all the possible palettes for each pixel (what Go's draw.Draw does)
- Fast: Generating clusters of pixels, then cutting the biggest in half on their **median** element until the image has <= N clusters (what https://github.com/soniakeys/quant does)
- Fastest: Adding all the pixel colors to an **octree** (tree with 8 children per node), then pruning the tree bottom-up until it has <= N leafs (**this repo**)In practice, this library can be typically used to render SIXEL images fast.
On a typical system, encoding a 1000x1000 image takes:
- 2s with the brute-force algorithm
- 0.8s with the median algorithm
- 0.3s with this repo's algorithm## Usage
```
go get github.com/delthas/octreequant@master
```The API is well-documented in its [![GoDoc](https://godocs.io/github.com/delthas/octreequant?status.svg)](https://godocs.io/github.com/delthas/octreequant)
To convert an image to a paletted image with a 256-color palette:
```
var in image.Image // = ...
out := octreequant.Paletted(in, 256)
```## Example
Before quantization:
![Original image](landscape.png)After quantization:
![Quantized image](landscape.quantized.png)## License
MIT