quantize

package module
v0.0.0-...-e960482 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2019 License: MIT Imports: 5 Imported by: 1

README

# quantize

This package reimplements hierarchical quantization described in this tutorial in Go programming language. Gonum was used instead of OpenCV, then latter replaced with simpler in-home matrix types and eigenvalue decomposition algorithm adapred from Java JAML package. This allowed to reduce ammount of needed dependencies. The effect and comparission with different Go packages can be found in this repository. Described eigenvalue method, while correct, in practice appears to be much slower than alternative methods, mostly based on some sort of k-means clustering. Therefore it doesn't really seem to be a good choice for a production code. It does a better job with detecting dominant background colors than some other competitors, though.

package main

import (
    "image"
    "image/color"
    _ "image/jpeg"
    _ "image/png"
    "os"

    "github.com/Nykakin/quantize"
    "github.com/joshdk/preview"
)   

func main() {
    f, err := os.Open("test.jpg")
    if err != nil {
        panic(err)
    }
    defer f.Close()
    img, _, err := image.Decode(f)
    if err != nil {
        panic(err)
    }

    quantizer := quantize.NewHierarhicalQuantizer()
    colors, err := quantizer.Quantize(img, 5)
    if err != nil {
        panic(err)
    }    

    palette := make([]color.Color, len(colors))
    for index, clr := range colors {
    	palette[index] = clr
    }

    // Display our new palette
    preview.Show(palette)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHierarhicalQuantizer

func NewHierarhicalQuantizer() hierarhicalQuantizer

Types

type ByCount

type ByCount []*colorNode

func (ByCount) Len

func (c ByCount) Len() int

func (ByCount) Less

func (c ByCount) Less(i, j int) bool

func (ByCount) Swap

func (c ByCount) Swap(i, j int)

type Quantizer

type Quantizer interface {
	Quantize(img image.Image, count int) ([]color.RGBA, error)
}

Jump to

Keyboard shortcuts

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