All Projects → obskyr → Colorgram.py

obskyr / Colorgram.py

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

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Colorgram.py

Pillow
The friendly PIL fork (Python Imaging Library)
Stars: ✭ 9,241 (+3097.58%)
Mutual labels:  image-processing, pillow
Optimize Images
A command-line interface (CLI) utility written in pure Python to help you reduce the file size of images.
Stars: ✭ 141 (-51.21%)
Mutual labels:  image-processing, pillow
Wb srgb
White balance camera-rendered sRGB images (CVPR 2019) [Matlab & Python]
Stars: ✭ 101 (-65.05%)
Mutual labels:  image-processing, color
global-color-picker
start the script and click anywhere to get rgb value at the cursor location
Stars: ✭ 31 (-89.27%)
Mutual labels:  color, pillow
Imagegonord
A tool that can convert your rgb images to nordtheme palette
Stars: ✭ 105 (-63.67%)
Mutual labels:  image-processing, pillow
Primify
Embed any image into a prime number.
Stars: ✭ 266 (-7.96%)
Mutual labels:  image-processing, pillow
Optimizedimageenhance
Several image/video enhancement methods, implemented by Java, to tackle common tasks, like dehazing, denoising, backscatter removal, low illuminance enhancement, featuring, smoothing and etc.
Stars: ✭ 272 (-5.88%)
Mutual labels:  image-processing
Inpainting
Want to remove something(someone) from a photo as it never was there? This is .NET implementation of content-aware fill. It smartly fills in unwanted or missing areas of photographs.
Stars: ✭ 280 (-3.11%)
Mutual labels:  image-processing
Colorpicker
jQuery UI widget for color picking (similar to the one in Microsoft Office 2010).
Stars: ✭ 271 (-6.23%)
Mutual labels:  color
Slicer
Multi-platform, free open source software for visualization and image computing.
Stars: ✭ 263 (-9%)
Mutual labels:  image-processing
Menpo
A statistical modelling toolkit, providing all the tools required to build, fit, visualize, and test deformable models.
Stars: ✭ 288 (-0.35%)
Mutual labels:  image-processing
Chalk
🖍 Terminal string styling done right
Stars: ✭ 17,566 (+5978.2%)
Mutual labels:  color
Swiftuix
Extensions and additions to the standard SwiftUI library.
Stars: ✭ 4,087 (+1314.19%)
Mutual labels:  color
Fvid
fvid is a project that aims to encode any file as a video using 1-bit color images to survive compression algorithms for data retrieval.
Stars: ✭ 276 (-4.5%)
Mutual labels:  pillow
Xcodecolorsense2
🍉 An Xcode source editor extension that shows hex color info
Stars: ✭ 281 (-2.77%)
Mutual labels:  color
Xcode One Dark
Atom One Dark theme for Xcode
Stars: ✭ 273 (-5.54%)
Mutual labels:  color
Recursive Bf
A lightweight C++ library for recursive bilateral filtering [Yang, Qingxiong. "Recursive bilateral filtering". European Conference on Computer Vision, 2012].
Stars: ✭ 287 (-0.69%)
Mutual labels:  image-processing
Culori
A comprehensive color library for JavaScript.
Stars: ✭ 271 (-6.23%)
Mutual labels:  color
Opencv Androidsamples
OpenCv samples for Android from OpenCV SDK using Android Studio and Gradle System
Stars: ✭ 278 (-3.81%)
Mutual labels:  image-processing
Crunch
Crunch is a tool for lossy PNG image file optimization. It combines selective bit depth, color type, and color palette reduction with zopfli DEFLATE compression algorithm encoding using the pngquant and zopflipng PNG optimization tools. This approach leads to a significant file size gain relative to lossless approaches at the expense of a relatively modest decrease in image quality (see example images below).
Stars: ✭ 3,074 (+963.67%)
Mutual labels:  image-processing

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 <https://github.com/darosh/colorgram-js>, a JavaScript library written by GitHub user @darosh <https://github.com/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

.. image:: http://i.imgur.com/BeReaRM.png :alt: 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 <https://github.com/fengsp/color-thief-py>__, takes about 1.05s).

Installation

You can install colorgram.py with pip <https://pip.pypa.io/en/latest/installing/>__, 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 '''''''

.. code:: python

import colorgram

# Extract 6 colors from an image.
colors = colorgram.extract('sweet_pic.jpg', 6)

# colorgram.extract returns Color objects, which let you access
# RGB, HSL, and what proportion of the image was that color.
first_color = colors[0]
rgb = first_color.rgb # e.g. (255, 151, 210)
hsl = first_color.hsl # e.g. (230, 255, 203)
proportion  = first_color.proportion # e.g. 0.34

# RGB and HSL are named tuples, so values can be accessed as properties.
# These all work just as well:
red = rgb[0]
red = rgb.r
saturation = hsl[1]
saturation = hsl.s

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:

.. code:: python

colors.sort(key=lambda c: c.hsl.h)
# or...
sorted(colors, key=lambda c: c.hsl.h)

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 <https://github.com/obskyr/colorgram.py/issues>__ 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!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].