colorpalette

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KMAccuracy = 0.01

KMAccuracy is he accuracy needed for convergence of the k-means algorithm used in function Create

View Source
var KMConsecutive = 2

KMConsecutive is the consecutive accuracy hits needed for convergence of the k-means algorithm used in function Create

View Source
var KMTimes = 3

KMTimes descibes how many times the Kmeans algorithm needs to be run with random start

View Source
var SampleFactor = 5

SampleFactor describes the fraction of pixels to be used in creating a palette.

Functions

func BW added in v0.9.4

func BW() color.Palette

BW returns a black and white color palette

func ConvHSLAtoRGBA

func ConvHSLAtoRGBA(hsla []float64) []float64

ConvHSLAtoRGBA converts between HSLA and RGBA color formats

func ConvRGBAtoHSLA

func ConvRGBAtoHSLA(rgba []float64) []float64

ConvRGBAtoHSLA converts between RGBA and HSLA color formats

func Create added in v0.6.0

func Create(img image.Image, k int) color.Palette

Create creates a new colorpalette using the k-means clustering algorithm

  • samplefactor: how many pixles to skip, during sampling for the creatrion of the KMeans problem's cluster points (higher means faster, because less points to iterate over)
  • kmTimes defines the amount of times to start the k-means algorithm with random init, the best output is choosen

func ToRGBA

func ToRGBA(origColor color.Color) color.RGBA

ToRGBA converts some color.Color into color.RGBA

Types

type ColorPalette

type ColorPalette struct {
	Name   string  `json:"name"`
	Colors [][]int `json:"colors"`
}

ColorPalette contains name and colors of one colorpalette

func CreatePLT added in v0.9.4

func CreatePLT(img image.Image, k int) ColorPalette

CreatePLT creates a new colorpalette using the k-means clustering algorithm

  • samplefactor: how many pixles to skip, during sampling for the creatrion of the KMeans problem's cluster points (higher means faster, because less points to iterate over)
  • kmTimes defines the amount of times to start the k-means algorithm with random init, the best output is choosen

func GetPaletteWithName

func GetPaletteWithName(name string, palettes []ColorPalette) *ColorPalette

GetPaletteWithName returns a specific from a slice of ColorPalette. The palette is specified by name. If there is none that matches, a black ColorPalette is returned.

func GetPalettesFromJSON

func GetPalettesFromJSON(jsonFileName string) []ColorPalette

GetPalettesFromJSON returns a slice of ColorPalettes after reading them from a JSON file.

func (*ColorPalette) ToJSONFile

func (colorpalette *ColorPalette) ToJSONFile(jsonFileName string)

ToJSONFile writes the given ColorPalette out to the specified path, as a JSON file (formatted).

func (*ColorPalette) ToJSONFileNoIndent added in v0.9.4

func (colorpalette *ColorPalette) ToJSONFileNoIndent(jsonFileName string)

ToJSONFileNoIndent writes the given ColorPalette out to the specified path, as a JSON file (formatted).

func (*ColorPalette) ToPalette

func (colorpalette *ColorPalette) ToPalette() color.Palette

ToPalette converts between this custom ColorPalette and the Go standard library color.Palette type struct

func (*ColorPalette) Traverse added in v0.9.4

func (colorpalette *ColorPalette) Traverse(img *image.Image, ltr bool, name string) (ColorPalette, int)

Traverse is used to find colours on one line in the image

Jump to

Keyboard shortcuts

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