extractor

package module
v0.0.0-...-5cefd61 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2019 License: GPL-3.0 Imports: 9 Imported by: 0

README

palette-extractor

Go Report Card GoDoc

This program extracts the dominant color or a representative color palette from an image.

Usage

Here's a simple example, where we build a 5 color palette:

package main

import (
	"fmt"
	"github.com/thomas-bouvier/palette-extractor"
)

func main() {
	// Creating the extractor object
	extractor := extractor.NewExtractor("image.png", 10)

	// Displaying the top 5 dominant colors of the image
	fmt.Println(extractor.GetPalette(5))
}

You can find the complete documentation on GoDoc.

Example

The following image has been used for this example:

Example

The program will give the following output when used with the image above:

[[234 231 230] [208 24 44] [59 41 37] [158 149 145] [145 126 114]]

Thanks

Many thanks to Lokesh Dhakar for his original work and Shipeng Feng for his implementation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Extractor

type Extractor struct {
	// contains filtered or unexported fields
}

Extractor represents the color palette extractor instance associated with a single image.

func NewExtractor

func NewExtractor(filename string, quality int) *Extractor

NewExtractor returns a new instance of an Extractor. The provider filename parameter can contain a path, and must include the file extension. The provided quality parameter behaves in the following manner: the bigger the number, the faster a color will be returned but the greater the likelihood that it will not be the visually most dominant color. 1 then refers the highest quality.

func NewPNGImageExtractor

func NewPNGImageExtractor(png image.Image, quality int) *Extractor

NewPNGImageExtractor ...

func (*Extractor) GetColor

func (extractor *Extractor) GetColor() []int

GetColor selects the dominant color. It corresponds to the first color in the palette. The color is returned as [r g b].

func (*Extractor) GetNumberOfColor

func (extractor *Extractor) GetNumberOfColor() int

GetNumberOfColor ...

func (*Extractor) GetPalette

func (extractor *Extractor) GetPalette(count int) [][]int

GetPalette builds a color palette. We are using the median cut algorithm to cluster similar colors. The provided count parameter defines how many colors should be extracted. Each color is returned as [r g b].

Jump to

Keyboard shortcuts

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