Skip to content
Find dominant color in images
Branch: master
Clone or download
Latest commit df772e8 Oct 20, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE add license Feb 21, 2015 update readme Oct 20, 2017
dominantcolor.go Fix 16 to 8-bit conversion Oct 10, 2017
dominantcolor_test.go fix example test Oct 20, 2017
firefox.png add test Feb 21, 2015
kmeancluster.go add test Feb 21, 2015



Find dominant color in images

import ""

Package dominantcolor provides a function for finding a color that represents the calculated dominant color in the image. This uses a KMean clustering algorithm to find clusters of pixel colors in RGB space.

The algorithm is ported from Chromium source code:

See more at:


package main

import (
	_ "image/jpeg"
	_ "image/png"

func FindDomiantColor(fileInput string) (string, error) {
	f, err := os.Open(fileInput)
	defer f.Close()
	if err != nil {
		fmt.Println("File not found:", fileInput)
		return "", err
	img, _, err := image.Decode(f)
	if err != nil {
		return "", err

	return dominantcolor.Hex(dominantcolor.Find(img)), nil

func main() {


You can’t perform that action at this time.