gocolors

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

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

Go to latest
Published: Apr 19, 2019 License: MIT Imports: 15 Imported by: 0

README

A simple program to extract a palette from a picture.

Image manipulation in Golang.

The task to extract a color palette from a picture is always arbitrary, and the approach of this program is to: blur -> resize -> kmeans cluster.

Dependency

https://github.com/esimov/stackblur-go

https://github.com/nfnt/resize

https://github.com/muesli/kmeans

https://github.com/parnurzeal/gorequest

Usage

To install

go get github.com/yiwenwang9702/gocolors

Results can be refined by accessing the Colormind API (http://colormind.io/). According to the website, their algorithm is a pretrained GAN that refines or completes a palette.

An example is available under the Examples directory.

Compared to blurring and resizing, clustering does not seem to be a good idea. Its optimization focuses too much on including all colors present, while we only try to find the important ones.

Features in Progress

Extracting colors by performing a clustering analysis seems to work well on real world pictures. But for the pictures created artificially, where a lot of pixels can have the exactly same RGB values, clustering does not seem to be a good idea.

Might write a port of colorgram.py (https://github.com/obskyr/colorgram.py). Which exploits the idea of sampling.

Might add a function to sort the palette in some way.

Is outlier detection a good idea here?

Ongoing.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePalette

func CreatePalette(colorslice ColorSlice) image.Image

CreatePalette ... creates a palette image.

func SaveImage

func SaveImage(m image.Image, savename string)

SaveImage ... a simple writer function.

Types

type Color

type Color [4]uint32

Color ... a slice representing R, G, B, A.

type ColorHSL

type ColorHSL [3]int

ColorHSL ... a slice representing H, S, L.

func HSL

func HSL(c Newcolor) ColorHSL

HSL ... converts R, G, B into H, S, L.

type ColorSlice

type ColorSlice []Newcolor

ColorSlice ... a slice or RGB colors.

func ExtractByKmeans

func ExtractByKmeans(filename string, k int, alpha float64) (ColorSlice, error)

ExtractByKmeans ... returns a slice of colors in RGB. The basic approach: blur, resize, kmeans cluster.

func Parser

func Parser(result string) ColorSlice

Parser ... parses the json result from Colormind API.

func Refine

func Refine(clustered ColorSlice) (ColorSlice, error)

Refine ... takes advantage of the Colormind API.

type Newcolor

type Newcolor [3]int

Newcolor ... a slice representing R, G, B.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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