paletter

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2020 License: GPL-3.0 Imports: 16 Imported by: 2

README

Paletter

Paletter is a CLI app and library to extract a color palette from an image through clustering (k-Means)

Example output:

Unsplash (Anders Jildén), Vernazza

Installation

To install paletter just use:

$ go get -u -v github.com/Baldomo/paletter

To install the CLI app use:

$ go get -u -v github.com/Baldomo/paletter/cmd/paletter
Usage (CLI)
Usage: paletter [OPTIONS] <IMAGE>
Flags:
  -colors int
        Number of colors to extract from the image (default 7)
  -html
        Output an html page
  -out string
        Set output file name/path
  -png
        Output a png image (default true)

The CLI app outputs png images of resolution dependent on the source image (see genimage.go for calculations), with the extracted palette ordered by lightness from left to right


Notes
  • Paletter uses the CIE L*a*b* color space both for the simplicity of its representation and it being device-indipendent
  • The k-Means implementation included in paletter is the naive one (muesli/kmeans)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeltaThreshold = 0.05

Controls delta threshold for k-means iterations (stops iterating when less than N percent points changed cluster assignment)

Functions

func CalculatePalette

func CalculatePalette(obs clusters.Observations, nColors int) (clusters.Clusters, error)

Extracts a given number of colors (as cluster centers) from Observations through naive k-Means clustering

func ColorsFromClusters

func ColorsFromClusters(cs clusters.Clusters) []colorful.Color

Converts Clusters centers to a color palette of a given number of colors. Each color gets 3 center values as floats (L*, a* and b* - the cluster space for an image is 3-dimensional)

func ImageToObservation

func ImageToObservation(img image.Image) clusters.Observations

Extracts Observations from a given Image. Each pixel is converted to colorful.Color, then unpacked in its raw L*, a* and b* values as floats

func OpenImage

func OpenImage(imgPath string) (image.Image, error)

Utility function that opens a file and loads its content into an image.Image

func WriteHTML

func WriteHTML(imgPath string, outFileName string, colors []colorful.Color) error

Creates an HTML document containing the original image and the color palette through a template with predefined layout

func WriteImage

func WriteImage(imgPath string, outFileName string, colors []colorful.Color) error

Serializes a list of colors (palette) into an image with a defined layout, containing the original image and the palette

Types

type ColorLab

type ColorLab struct {
	L, A, B float64
}

Represent color as lightness (L), green (-) to red (+) (A) and blue (-) to yellow (+) (B). Using floats instead of converting to other color space makes computing distance much faster, while keeping the computations accurate as L*a*b* values are represented linearly. ColorLab implements clusters.Observation

func (ColorLab) Coordinates

func (c ColorLab) Coordinates() clusters.Coordinates

Returns coordinates as a Coordinates object (slice of float64's)

func (ColorLab) Distance

func (c ColorLab) Distance(pos clusters.Coordinates) float64

Computes squared distance between `c` and another color (as Coordinates)

type Palette

type Palette []ColorLab

Palette implements sort.Interface

func (Palette) Len

func (p Palette) Len() int

Returns the number of elements in Palette

func (Palette) Less

func (p Palette) Less(i, j int) bool

Sorts colors by lightness, in descending order

func (Palette) Swap

func (p Palette) Swap(i, j int)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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