quantize

package module
v0.0.0-...-65999d3 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2017 License: MIT Imports: 3 Imported by: 0

README

License GoDoc Go Report Card CircleCI CodeCov

Quantize

🎨 Simple color palette quantization using MMCQ

Installing

You can fetch this library by running the following

go get -u github.com/joshdk/quantize

Usage

import (
	"image/color"
	"image/jpeg"
	"net/http"
	"github.com/joshdk/preview"
	"github.com/joshdk/quantize"
)

// Fetch the source image
resp, err := http.Get("https://blog.golang.org/gopher/plush.jpg")
if err != nil {
	panic(err.Error())
}

// Decode jpeg contents
img, err := jpeg.Decode(resp.Body)
if err != nil {
	panic(err.Error())
}

// Reduce image into a palette of 8 colors
colors := quantize.Image(img, 3)

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

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

As an example, we can reduce a photo of the Go Gopher (source) into a color palette.

gopher

License

This library is distributed under the MIT License, see LICENSE.txt for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Average

func Average(pixels []color.RGBA) color.RGBA

Average takes in a slice of RGB pixels, and returns the average across the red, green, & blue components of all pixels.

func Image

func Image(img image.Image, levels int) []color.RGBA

Image is a helper that converts the given image into a slice of RGB pixels before performing MMCQ.

func Partition

func Partition(pixels []color.RGBA) ([]color.RGBA, []color.RGBA)

Partition takes in a slice of RGB pixels, and bisects the slice with respect to the color component with the largest spread.

func Pixels

func Pixels(pixels []color.RGBA, levels int) []color.RGBA

Pixels takes in a slice of RGB pixels, and performs the MMCQ process to the specified number of levels. Returns a slice of RGB colors of length 2^levels.

func Spread

func Spread(pixels []color.RGBA) (uint8, uint8, uint8)

Spread takes in a slice of RGB pixels, and returns the delta across the red, green, & blue components of all pixels.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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