camalian

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: MIT Imports: 10 Imported by: 0

README

Camalian-Go

Go Report Card GitHub license Build codecov

Color extraction utility in Golang

For details information on the utility please look at the following article. Advance Color Quantization with Camalian. This implementation in Golang inspired by Camalian Ruby Implementation.

Usage

Binary Usage

To use the binary binary for utility. Install it with:

$ GO111MODULE=on go get -u "github.com/nazarhussain/camalian-go/cmd/camalian"

The usage is as follows:

$ camalian --help

Usage:
   camalian <path> {flags}

Commands: 
   help                          displays usage information
   version                       displays version number

Arguments: 
   path                          Path to the image file

Flags: 
   -h, --help                    displays usage information of the application or a command (default: false)
   -n, --number                  Number of colors to extract (default: 15)
   -q, --quantizer               Quantizer to use. histogram, kmeans, median_cut (default: histogram)
   -v, --version                 displays version number (default: false)
Library Usage

Mention the package as your project mode dependencies.

import (
  camalian "github.com/nazarhussain/camalian-go"
  quantizers "github.com/nazarhussain/camalian-go/quantizers"

Then use as following:

path := "path/to/image/file"
palette := new(camalian.Palette).BuildFromImage(&camalian.Image{FilePath: path})
palette = palette.Quantize(quantizers.Histogram{}, 10)

fmt.Println(palette.ToHex())

Available Quantizers are quantizers.Histogram{}, quantizers.KMeans{} and quantizers.MedianCut{}.

For more details on each quantizers please check this section.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Color

type Color struct {
	RGB
	HSV HSV
	HSL HSL
}

func (*Color) Build

func (c *Color) Build(r, g, b uint8, buildAll bool) *Color

Build Color object from rgb values Specify buildAll = true if you want to calculate HSL/HSV values as well

func (*Color) BuildFromHex

func (c *Color) BuildFromHex(hex string, buildAll bool) (*Color, error)

Build Color object from Hex string e.g. #FF7913 Specify buildAll = true if you want to calculate HSL/HSV values as well

func (*Color) HueDistance

func (c *Color) HueDistance(c2 *Color) uint16

Calculate Hue distance between two colors

func (*Color) RgbDistance

func (c *Color) RgbDistance(c2 *Color) float64

Calculate RGB distance between two colors

func (*Color) ToHex

func (c *Color) ToHex() string

type HSL

type HSL struct {
	H uint16
	S float32
	L float32
}

type HSV

type HSV struct {
	H uint16
	S float32
	V float32
}

type Image

type Image struct {
	FilePath string
}

The Image construct which implements camalian.Quantizeable interface

func (*Image) Pixels

func (i *Image) Pixels() []RGB

type Palette

type Palette []*Color

func (*Palette) AverageColor

func (p *Palette) AverageColor() *Color

Calculate avargage color in RGB Color Space for the whole palette

func (*Palette) BuildFromHex

func (p *Palette) BuildFromHex(colors ...string) (*Palette, error)

Build color palette from hex strings

new(Palette).BuildFromHex("#FF0000", "#00FF00")

func (*Palette) BuildFromImage

func (p *Palette) BuildFromImage(source Quantizeable) *Palette

Build color palette from a Quantizeable interface

func (*Palette) Common

func (p *Palette) Common(p2 *Palette) *Palette

Fetch common colors among two color palettes

func (*Palette) LightColors

func (p *Palette) LightColors(limit1, limit2 uint16) *Palette

Filter colors in particular range for lightness in HSL color space

func (*Palette) Quantize

func (p *Palette) Quantize(q Quantizer, count uint) *Palette

Quantize the palette by specific Quantizer for given number of colors

func (*Palette) SortBy

func (p *Palette) SortBy(v SortProperty, order bool) *Palette

Sort color palette by some properties

func (*Palette) SortSimilarColors

func (p *Palette) SortSimilarColors() *Palette

Sort palette to visually similar colors

func (*Palette) ToHex

func (p *Palette) ToHex() []string

func (*Palette) Unique

func (p *Palette) Unique() *Palette

Remove redundant colors in palette and get unique colors

type Quantizeable

type Quantizeable interface {
	Pixels() []RGB
}

The interface to fetch any quantizeable object

type Quantizer

type Quantizer interface {
	Quantize(*Palette, uint) *Palette
}

The interface to to quantizer algorithm

type RGB

type RGB struct {
	R uint8
	G uint8
	B uint8
}

type SortProperty

type SortProperty int
const (
	HSLHue SortProperty = iota
	HSLSaturation
	HSLLightness
	HSVHue
	HSVSaturation
	HSVValue
	Red
	Green
	Blue
)

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

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