treepalette

An indexed color palette implementation in Go on top of a k-d tree for fast color lookups. Also rank a palette against an image to identify prominent colors.
- Transparent(RGBA) and opaque(RGB) palettes
- Direct image conversion
- Image pixel counting and color ranking, for prominent color analysis
kd-tree implementation adapted from: kyroy/kdtree
Usage
go get github.com/philoj/tree-palette
import "github.com/philoj/tree-palette"
Create a color model for color lookups.
m := NewPalettedColorModel([]color.Color{
}, false
)
equivalentColor := m.Convert(someColor)
Color ranking and image color analysis
Start by implementing treepalette.PaletteColor
and treepalette.Color
interfaces:
type Color interface {
Dimensions() int
Dimension(i int) uint32
}
type PaletteColor interface {
Color
Index() int
}
Or use included implementations treepalette.ColorRGBA
and treepalette.IndexedColorRGBA
respectively:
c := treepalette.NewOpaqueColor(121,201,10)
p1 := treepalette.NewOpaquePaletteColor(255, 130, 1, 2, "DARK ORANGE")
p2 := treepalette.NewOpaquePaletteColor(1, 128, 181, 11, "PACIFIC BLUE")
palette := treepalette.NewPalette([]treepalette.PaletteColor{p1,p2}, false)
equivalent := palette.Convert(c)
palettedImage := palette.ApplyPalette(img)
colors, colorCount := palette.Rank(img)
fmt.Printf("Most frequent color is %s. It appears %d times.", colors[0], colorCount[colors[0].Index()])