GithubHelp home page GithubHelp logo

srinivas365 / color-palettes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from a-poor/color-palettes

0.0 1.0 0.0 23.21 MB

Using clustering algorithms to create color palettes from movie stills

Home Page: https://towardsdatascience.com/algorithmic-color-palettes-a110d6448b5d

License: GNU General Public License v3.0

Jupyter Notebook 99.99% Python 0.01%

color-palettes's Introduction

Color Palettes in Movies

sample-palette-1.png

Binder NBViewer

by Austin Poor

Using clustering algorithms to create color palettes from movie stills.

Info

The notebook color-palettes.ipynb goes through using both K-Means and Agglomerative clustering to create color palettes from images.

The sample images come from the film Only God Forgives (2013) and the stills came from the site FILMGRAB.

I chose to use KMeans and Agglomerative clustering for their speed and in order to get a definite color palette size after running the algorithm.

In addition to clustering the images' RGB (red-green-blue) values, I applied the same algorithms on the images' HSV (hue-saturation-value) values.

Running the Notebook

You can run the notebook using binder, here.

Or you can download the notebook and run it (requirements.txt).

Note that the algorithms have only been tested on images with 3 color-channels.

Issues

sample-palette-2.png

The clustering algorithms tend to pick more commonly occuring colors even if they're similar.

For example, if you look at the above image, the colors red (from the standing boxer and boxing rope) or blue (from the KO-ed boxer or the mat) seem to stand out, even though they don't take up a lot of the frame.

But the palette generated using K-Means clustering didn't include either and instead picked colors that were more similar and more abundant.

When creating palettes using HSV color representations, both clustering algorithms included a blue but not a red in the palette.

Some possible solutions would be increasing the palette size, adjusting other hyperparameters for the clustering algorithms, or using different clustering algorithms altogether.

Flask App

In addition to the notebook, I created simple flask-app-API for creating color palettes.

The flask app can be found here: flask-app/app.py

and the color-palette code is in a separate file here: flask-app/make_palette.py

With the flask app running, you can make API calls with the following:

import requests

FLASK_URL = "http://localhost:5000"
IMG_URL = "https://film-grab.com/wp-content/uploads/photo-gallery/Colour_Out_of_Space_046.jpg?bwg=1598860186"

response = requests.get(
    FLASK_URL,
    parameters={"url":IMG_URL}
)
print("Color palette:", response.json())

The API doesn't include options for picking the clustering algorithm or setting the size of the palette, but those changes should be pretty easy to make.

color-palettes's People

Contributors

a-poor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.