Coder Social home page Coder Social logo

pandinosaurus / colorgram.py Goto Github PK

View Code? Open in Web Editor NEW

This project forked from obskyr/colorgram.py

0.0 0.0 0.0 1.13 MB

A Python module for extracting colors from images. Get a palette of any picture!

License: MIT License

Python 85.42% JavaScript 14.58%

colorgram.py's Introduction

colorgram.py

colorgram.py is a Python library that lets you extract colors from images. Compared to other libraries, the colorgram algorithm's results are more intense.

colorgram.py is a port of colorgram.js, a JavaScript library written by GitHub user @darosh. The goal is to have 100% accuracy to the results of the original library (a goal that is met). I decided to port it since I much prefer the results the colorgram algorithm gets over those of alternative libraries - have a look in the next section.

Results

Results of colorgram.py on a 512x512 image

Time-wise, an extraction of a 512x512 image takes about 0.66s (another popular color extraction library, Color Thief, takes about 1.05s).

Installation

You can install colorgram.py with pip, as following:

pip install colorgram.py

How to use

Using colorgram.py is simple. Mainly there's only one function you'll need to use - colorgram.extract.

Example

colorgram.extract(image, number_of_colors)

Extract colors from an image. image may be either a path to a file, a file-like object, or a Pillow Image object. The function will return a list of number_of_colors Color objects.

colorgram.Color

A color extracted from an image. Its properties are:

  • Color.rgb - The color represented as a namedtuple of RGB from 0 to 255, e.g. (r=255, g=151, b=210).
  • Color.hsl - The color represented as a namedtuple of HSL from 0 to 255, e.g. (h=230, s=255, l=203).
  • Color.proportion - The proportion of the image that is in the extracted color from 0 to 1, e.g. 0.34.

Sorting by HSL

Something the original library lets you do is sort the colors you get by HSL. In actuality, though, the colors are only sorted by hue (as of colorgram.js 0.1.5), while saturation and lightness are ignored. To get the corresponding result in colorgram.py, simply do:

Contact

If you find a bug in the colorgram.py, or if there's a feature you would like to be added, please open an issue on GitHub.

If you have a question about the library, or if you'd just like to talk about, well, anything, that's no problem at all. You can reach me in any of these ways:

To get a quick answer, Twitter is your best bet.

Enjoy!

colorgram.py's People

Contributors

nleroy917 avatar obskyr 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.