Giter Club home page Giter Club logo

kmeanspainting's Introduction

kMeansPainting

Given a picture and a number k, this script outputs a version of your picture that only uses k colors. But it picks those k colors wisely (using the k-Means Clustering Algorithm) so as to preserve the original context of the image. You'd be amazed how much trendier you look with fewer colors.

##How to run the script

  1. Get the file entitled kMeansColor.py (can be done by downloading the zip file of this repo on github)

  2. Install dependencies, of which there are two: SciPy and PIL (Python Imaging Library). If you're a Mac-user you can install these by simply entering the following into the Terminal (you'll be prompted for your computer password):

sudo port install py27-scipy
sudo port install py27-pil
  1. Run the code by entering the following into your terminal:
python2.7 kMeansPainting.py [filepath to picture] [number k]

Note that your terminal needs to be in the folder containing kMeansPainting.py; if this is not the case, then enter cd [path to folder containing kMeansPainting.py] before running the above line of code.

When the script is complete, a new version of your image will appear containing only the most identifying k colors (it will NOT overwrite your original image). Most jpg/png files take ~2 seconds to complete, while high-resolution photos may take up to a minute (pending further testing).

  1. Report errors that you encounter by letting me know (email: [email protected], twitter: @nikhilhyphen). I hacked this together quickly and haven't done much error handling or testing for corner cases, so let me know if you run into issues and I can update the code accordingly!

##Example ###Original vs. k=2: barca barca2

kmeanspainting's People

Contributors

nikhilnathwani avatar

Watchers

 avatar  avatar

Forkers

isheu2014

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.