Colour Extraction

Extracting the dominant colours from an image using k-means clustering.

Introduction

From Wikipedia

In data mining, k-means clustering is a method of cluster analysis which aims to partition n observations into k clusters in which each observation belongs to the cluster with the nearest mean. This results in a partitioning of the data space into Voronoi cells.

By modelling the pixels of an image as points within a 3-dimensional colourspace (such as RGB) we can use k-means clustering to partition the colourspace into voronoi cells.

Demo

Written in javascript, this demo uses a Worker to perform k-means clustering in the background. This keeps the user interface responsive and allows computationally expensive analysis to be performed within the browser. It also requires support for Canvas and Blob.

Source

The source code is available from github.com/bailus/kmean

Github statistics


The above software is licensed under the MIT License.