Expand description
A-Sixel library for encoding sixel images.
§Basic Usage
use a_sixel::BitMergeSixelEncoderBest;
use image::RgbaImage;
let img = RgbaImage::new(100, 100);
println!("{}", <BitMergeSixelEncoderBest>::encode(img));
§Choosing an Encoder
- I want good quality:
- I’m time constrained:
- Use
BitMergeSixelEncoderLow
, orBitSixelEncoder
.
- Use
- I’m really time constrained and can sacrifice a little quality:
For a more detailed breakdown, here’s the encoders by average speed and quality against the test images (speed figures will vary) at 256 colors with Sierra dithering:
Algorithm | MSE | DSSIM | PHash Distance | Mean ΔE | Max ΔE | ΔE >2.3 | ΔE >5.0 | Execution Time (ms) |
---|---|---|---|---|---|---|---|---|
adu | 15.07 | 0.0053 | 8.66 | 1.79 | 12.88 | 31.6% | 4.4% | 1416 |
bit | 35.82 | 0.0132 | 31.14 | 3.16 | 11.03 | 64.5% | 15.1% | 426 |
bit-no-dither | 31.78 | 0.0214 | 39.10 | 3.09 | 10.23 | 64.0% | 13.4% | 274 |
bit-merge-low | 10.67 | 0.0038 | 13.97 | 1.95 | 9.98 | 32.4% | 2.2% | 785 |
bit-merge | 10.36 | 0.0037 | 13.55 | 1.89 | 10.01 | 31.0% | 2.2% | 932 |
bit-merge-better | 10.31 | 0.0037 | 13.45 | 1.85 | 10.21 | 30.6% | 2.2% | 1275 |
bit-merge-best | 10.29 | 0.0037 | 13.52 | 1.83 | 10.26 | 30.6% | 2.2% | 1496 |
focal | 14.62 | 0.0056 | 19.97 | 2.30 | 9.16 | 45.3% | 3.3% | 2428 |
k-means | 10.07 | 0.0036 | 13.07 | 1.80 | 10.17 | 29.1% | 2.2% | 2996 |
k-medians | 17.67 | 0.0068 | 21.07 | 2.61 | 10.17 | 53.6% | 5.1% | 7305 |
median-cut | 19.63 | 0.0059 | 16.45 | 2.24 | 10.36 | 42.2% | 5.9% | 692 |
octree | 54.48 | 0.0148 | 26.03 | 3.89 | 12.49 | 78.6% | 25.4% | 682 |
wu | 17.89 | 0.0068 | 21.03 | 2.34 | 10.24 | 46.3% | 5.1% | 1853 |
Note: Execution time includes the time taken to compute error statistics - this is non-trivial. For example, exclusive of error statistics computation, bit-no-dither takes <100ms on average. Performance figures will vary based on machine, etc. They are only useful for comparing algorithms against each other within this dataset.
Here’s the encoders at 16 colors with Sierra dithering:
Algorithm | MSE | DSSIM | PHash Distance | Mean ΔE | Max ΔE | ΔE >2.3 | ΔE >5.0 | Execution Time (ms) |
---|---|---|---|---|---|---|---|---|
adu | 116.85 | 0.036 | 39.83 | 4.02 | 18.39 | 66% | 33% | 332 |
bit | 178.47 | 0.049 | 59.79 | 5.53 | 16.61 | 89% | 51% | 307 |
bit-merge | 95.17 | 0.030 | 41.52 | 3.95 | 16.16 | 67% | 31% | 712 |
focal | 118.57 | 0.035 | 48.59 | 4.36 | 16.88 | 72% | 34% | 2150 |
k-means | 99.36 | 0.031 | 43.10 | 3.99 | 16.41 | 67% | 31% | 637 |
k-medians | 166.88 | 0.050 | 60.59 | 5.48 | 16.77 | 88% | 52% | 5447 |
median-cut | 164.52 | 0.037 | 45.28 | 4.68 | 16.72 | 74% | 42% | 374 |
octree | 459.37 | 0.085 | 75.07 | 7.69 | 18.89 | 98% | 74% | 446 |
wu | 125.84 | 0.039 | 50.52 | 4.48 | 16.70 | 75% | 39% | 906 |
Re-exports§
pub use crate::adu::ADUPaletteBuilder;
adu
pub use crate::bit::BitPaletteBuilder;
pub use crate::bitmerge::BitMergePaletteBuilder;
bit-merge
pub use crate::focal::FocalPaletteBuilder;
focal
pub use crate::kmeans::KMeansPaletteBuilder;
k-means
pub use crate::kmedians::KMediansPaletteBuilder;
k-medians
pub use crate::median_cut::MedianCutPaletteBuilder;
median-cut
pub use crate::octree::OctreePaletteBuilder;
octree
pub use crate::wu::WuPaletteBuilder;
wu
Modules§
- adu
adu
- Use Adaptive Distributive Units to “learn” the image’s color properties and select palette entries.
- bit
- Encodes a palette by bucketing bit ranges into a power of two number of buckets. This is very fast and produces ok results for most images at larger palette sizes (e.g. 256).
- bitmerge
bit-merge
- Uses
BitSixelEncoder
with k-means and agglomerative merging to build a palette. - dither
- A collection of various dithering algorithms that can be used with the
SixelEncoder
to dither the result. - focal
focal
- Use weighted pixels based on the image’s spectral properties to provided weighted input to k-means.
- kmeans
k-means
- Use k-means clustering to determine a palette for the image.
- kmedians
k-medians
- Uses k-medians to build a palette of colors.
- median_
cut median-cut
- https://en.wikipedia.org/wiki/Median_cut
- octree
octree
- Uses an octree to build a palette from an image.
- wu
wu
- Uses Wu’s quantization algorithm to build a palette from an image.
Structs§
- Sixel
Encoder - The main type for performing sixel encoding.
Traits§
- Palette
Builder - A trait for types that perform quantization of an image to a target palette size.
Type Aliases§
- ADUSixel
Encoder adu
- BitMerge
Sixel Encoder bit-merge
- BitMerge
Sixel Encoder Best bit-merge
- BitMerge
Sixel Encoder Better bit-merge
- BitMerge
Sixel Encoder Low bit-merge
- BitSixel
Encoder - Focal
Sixel Encoder focal
- KMeans
Sixel Encoder k-means
- KMedians
Sixel Encoder k-medians
- Median
CutSixel Encoder median-cut
- Octree
Sixel Encoder octree
- WuSixel
Encoder wu