• Stars
    star
    137
  • Rank 264,675 (Top 6 %)
  • Language
    JavaScript
  • Created almost 8 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Palette Maker is an interactive web tool that allows you to explore different approaches to extract color palettes from images

palette-maker

Palette Maker is an interactive web tool that allows you to explore different approaches to extract color palettes from images. For a detailed description, please refer to this blog post that I wrote.

A demo can be found here.

Development

Setup

To run the project:

  • Clone the repository

  • Install the dependencies by running:

npm install
  • Build and package the javascript by running:
webpack

This will generate a single bundle.js file, containing all of the code.

Running Locally

After building the bundle.js file, the app can be run a few different ways.

Using Express

The app is configured to work with express for remote deployments (e.g., Heroku). To run it locally, simply use:

npm start

Using http-server

Since the app runs entirely inside of the browser, you can use http-server to serve up the files locally.

npm install http-server -g

Then, navigate to the project root and run:

http-server ./public

Future Work

I would like to add the following in the future:

  • Features

    • Additional color spaces (e.g., HSL).
    • Additional algorithms - perhaps other clustering techniques or image sampling.
    • Improve the design of the extracted palettes, and make them more exportable.
    • Add sample images.
  • Code Improvements

    • Add a lightweight JS framework for better code readability and organization (probably React).
    • Update the Plotly.js imports.
    • Improve the page responsiveness when the algorithms run and provide progress feedback.

Features

When the app starts, you simply browse and select a local image. The app then loads the image and plots in in three dimensional RGB space.

Palette Extraction Algorithms

Three different palette extraction algorithms are currently supported.

Simple Histogram Binning

The histogram binning approach partitions the RGB space into a NxNxN grid where N is a user provided value. The below image shows an example when N=3. Here, the space is partitioned into 27 equally sized cells. The pixels that fall within each cell are counted, and their average color value is computed. Average colors from the most populated 10 cells are selected and displayed as the color palette.

Median Cut Space Partitioning

Median cut also partitions the space, though it does to in a non-uniform way. The pixel range is computed for each color dimension (red, green, and blue). Then, the dimention with the largest range is selected, and the median value is computed. The space is then split into two halves - one above the median, and one below. This process continues recursively. Each iteration, only the subspace with greatest pixel range is split. A sample partitioning looks like this:

K-Means Clustering

K-Means attempts to cluster the pixels into k distinct clusters. The user provides a k value as input.

Since k-means is notorious for getting stuck in local minima, the algorithm is re-run 10 times and the result with lowest error is selected. An example output from running k-means on the above image is shown below.

More Repositories

1

GradientDescentExample

Example demonstrating how gradient descent may be used to solve a linear regression problem
Python
535
star
2

MeanShift_py

Simple implementation of mean shift clustering in python
Python
286
star
3

MeanShift_cpp

Mean shift clustering Implementation in C++
C++
90
star
4

react-redux-typescript

Project template for projects that use React, Redux, and TypeScript
TypeScript
38
star
5

CentralLimitTheoremDemo

Python
25
star
6

ruby-excel-library-examples

Example code for reading Excel files in ruby with different libraries.
Ruby
23
star
7

S3.FMA

Amazon S3 File Manager API in Python. S3.FMA is a thin wrapper around boto to perform specific high level file management tasks on an AWS S3 Bucket.
Python
20
star
8

swift-type-inference-bug

This project contains code that reproduces a bug that prevents the Swift compiler from being able to efficiently perform type inference on semi-simple dictionary or array literals.
Swift
17
star
9

beacon-scanner

Swift
14
star
10

ibeacon-finder

Simple iOS iBeacon app skeleton in Swift. Searches for an iBeacon in monitoring and ranging mode and prints results. This app contains no meaningful UI.
Swift
11
star
11

SwiftForecast

API Wrapper around The Dark Sky Forecast API in Swift
Swift
4
star
12

rickshaw_examples

HTML
4
star
13

react-native-demo-project

Simple cross platform app written with react native. Uses cross platform tabbed navigation, and loads and displays trending gifs from Giphy
JavaScript
2
star
14

spacemacs-configuration

Personal Spacemacs dotfile
Emacs Lisp
2
star
15

DataStructuresCSharp

Data structure implementations in C#
C#
1
star
16

algorithms

implementations for various algorithms
C#
1
star
17

AlgorithmsPython

Implementations of various algorithms in python
Python
1
star