{"id":13714349,"url":"https://github.com/philoj/tree-palette","last_synced_at":"2026-03-13T15:03:13.089Z","repository":{"id":57564484,"uuid":"335541213","full_name":"philoj/tree-palette","owner":"philoj","description":"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.","archived":false,"fork":false,"pushed_at":"2021-02-05T08:39:16.000Z","size":282,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T01:40:51.725Z","etag":null,"topics":["color","color-analysis","dominant-color","go","golang","image-procesing","image-processing","kd-tree","nearest-neighbor-search","palette","prominent-colors","rgba","tree-structure"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/philoj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-03T07:24:01.000Z","updated_at":"2024-02-27T14:50:47.000Z","dependencies_parsed_at":"2022-09-18T04:21:32.777Z","dependency_job_id":null,"html_url":"https://github.com/philoj/tree-palette","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/philoj/tree-palette","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philoj%2Ftree-palette","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philoj%2Ftree-palette/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philoj%2Ftree-palette/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philoj%2Ftree-palette/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/philoj","download_url":"https://codeload.github.com/philoj/tree-palette/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philoj%2Ftree-palette/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30469131,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-13T11:00:43.441Z","status":"ssl_error","status_checked_at":"2026-03-13T11:00:23.173Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["color","color-analysis","dominant-color","go","golang","image-procesing","image-processing","kd-tree","nearest-neighbor-search","palette","prominent-colors","rgba","tree-structure"],"created_at":"2024-08-02T23:01:57.606Z","updated_at":"2026-03-13T15:03:13.024Z","avatar_url":"https://github.com/philoj.png","language":"Go","funding_links":[],"categories":["Repositories"],"sub_categories":[],"readme":"# treepalette\n\n[![GoDoc](https://godoc.org/github.com/philoj/tree-palette?status.svg)](https://godoc.org/github.com/philoj/tree-palette)\n[![Build Status](https://travis-ci.com/philoj/tree-palette.svg?branch=main)](https://travis-ci.com/github/philoj/tree-palette)\n[![codecov](https://codecov.io/gh/philoj/tree-palette/branch/main/graph/badge.svg?token=TAIOSNJZ8C)](https://codecov.io/gh/philoj/tree-palette)\n[![Go Report Card](https://goreportcard.com/badge/github.com/philoj/tree-palette)](https://goreportcard.com/report/github.com/philoj/tree-palette)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/kyroy/kdtree/blob/master/LICENSE)\n\nAn indexed color palette implementation in Go on top of a [k-d tree](https://en.wikipedia.org/wiki/K-d_tree) for fast color lookups. Also rank a palette against an image to identify prominent colors.\n\n- Transparent(RGBA) and opaque(RGB) palettes\n- Direct image conversion\n- Image pixel counting and color ranking, for prominent color analysis\n\nkd-tree implementation adapted from: [kyroy/kdtree](https://github.com/kyroy/kdtree)\n\n## Usage\n\n```bash\ngo get github.com/philoj/tree-palette\n```\n\n```go\nimport \"github.com/philoj/tree-palette\"\n````\n\n### Create a color model for color lookups.\n```go\nm := NewPalettedColorModel([]color.Color{\n        // list of colors in the palette\n        }, false // ignore alpha values\n    )\nequivalentColor := m.Convert(someColor)\n```\n\n\n### Color ranking and image color analysis\n\nStart by implementing `treepalette.PaletteColor` and `treepalette.Color` interfaces:\n\n```go\n// Color express A color as A n-dimensional point in the RGBA space for usage in the kd-tree search algorithm.\ntype Color interface {\n\n\t// Dimensions returns the total number of dimensions(3 for RGB, 4 for RGBA).\n\tDimensions() int\n\n\t// Dimension returns the value of the i-th dimension, say R,G,B and/or A.\n\tDimension(i int) uint32\n}\n\n// PaletteColor is A Color inside an indexed color palette.\ntype PaletteColor interface {\n\tColor\n\n\t// Index returns palette index of the color\n\tIndex() int\n}\n```\n\nOr use included implementations `treepalette.ColorRGBA` and `treepalette.IndexedColorRGBA` respectively:\n```go\n// Unknown color\nc := treepalette.NewOpaqueColor(121,201,10)\n\n// Palette colors\np1 := treepalette.NewOpaquePaletteColor(255, 130, 1, 2, \"DARK ORANGE\") // R,G,B, unique-id, name\np2 := treepalette.NewOpaquePaletteColor(1, 128, 181, 11, \"PACIFIC BLUE\")\n\n// Create palette\npalette := treepalette.NewPalette([]treepalette.PaletteColor{p1,p2}, false)\n\n// Equivalent color\nequivalent := palette.Convert(c)\n\n// Convert an image.Image\npalettedImage := palette.ApplyPalette(img)\n\n// Rank the palette against all the pixels in an image.Image\ncolors, colorCount := palette.Rank(img)\nfmt.Printf(\"Most frequent color is %s. It appears %d times.\", colors[0], colorCount[colors[0].Index()])\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphiloj%2Ftree-palette","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphiloj%2Ftree-palette","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphiloj%2Ftree-palette/lists"}