Giter VIP home page Giter VIP logo

color-thief-py's Introduction

Color Thief

A Python module for grabbing the color palette from an image.

Installation

$ pip install colorthief

Usage

from colorthief import ColorThief

color_thief = ColorThief('/path/to/imagefile')
# get the dominant color
dominant_color = color_thief.get_color(quality=1)
# build a color palette
palette = color_thief.get_palette(color_count=6)

API

class ColorThief(object):
    def __init__(self, file):
        """Create one color thief for one image.

        :param file: A filename (string) or a file object. The file object
                     must implement `read()`, `seek()`, and `tell()` methods,
                     and be opened in binary mode.
        """
        pass

    def get_color(self, quality=10):
        """Get the dominant color.

        :param quality: quality settings, 1 is the highest quality, the bigger
                        the number, the faster a color will be returned but
                        the greater the likelihood that it will not be the
                        visually most dominant color
        :return tuple: (r, g, b)
        """
        pass

    def get_palette(self, color_count=10, quality=10):
        """Build a color palette.  We are using the median cut algorithm to
        cluster similar colors.

        :param color_count: the size of the palette, max number of colors
        :param quality: quality settings, 1 is the highest quality, the bigger
                        the number, the faster the palette generation, but the
                        greater the likelihood that colors will be missed.
        :return list: a list of tuple in the form (r, g, b)
        """
        pass

Thanks

Thanks to Lokesh Dhakar for his original work.

Better

If you feel anything wrong, feedbacks or pull requests are welcome.

color-thief-py's People

Contributors

crazyzubr avatar fengsp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

color-thief-py's Issues

how do i get color count percentage?

hi, i am calling get_palette() function to get dominant colors and i need to have percentage of each color i mean when i get 6 color from this function i need to know how many pixels of that color in the image. how can i get that info?

get_palette() returns 1+color_count colors

dominant_color = ColorThief(image).get_palette(color_count=3, quality=10)
returns
[(47, 36, 65), (171, 176, 180), (139, 153, 171), (122, 134, 165)]
(with this particular image).

get_palette crashing on one image

Hi,

I've run get_palette on thousands of images with no issues. I have one jpg that it just crashes on. The message returned is "killed".

image

About complete white image having values (254,254,254)

The code will not be able to detect complete dominant white images with values like (254,254,254).

Please modify the code of get_palette() to:

r, g, b, a = pixels[i]
            # If pixel is mostly opaque and not white
            if a >= 125:
                if not (r > 255 and g > 255 and b > 255):
                    valid_pixels.append((r, g, b))

Setting the threshold of 250 is causing the problem

Does this still work

Screen Shot 2022-07-15 at 7 19 00 PM

I've tried and pycharm will not recognize or install via 'pip install colorthief` and i've already tried via conda but it will not install `color-thief-py`, `color-thief`, or `colorthief`

The repo files are looking like they are six to seven years old June 12 2015, and the last Pypi update was 2017 https://pypi.org/project/colorthief/

The RGB values get_palette is > 255

For a certain image the RBG value was (256, 252, 212) This value for R should not exists as RGB values are 32 bit values [0-255]. Cant share the image for privacy reasons.

Inaccurate results

The results provided by the python wrapper seem to vary a lot as compared to the results provided by https://lokeshdhakar.com/projects/color-thief/#examples

For example, here's the result of the website as compared to the result of the py wrapper.

Screenshot 2020-04-28 at 7 00 07 PM

RGB: (219,210,202)

Whereas the python wrapper gives the RGB output as (61, 54, 40)

I tried alternating the quality from 10 to 1 but I can't get a result close to the original result.

Pass in image to __init__ instead of filename

Sometimes you already have the image as a PIL Image object and re-reading as another Image is a wasted of memory. Currently, I'm re-implementing ColorThief like this:

# Overrides init of ColorThief to pass in the buffer from memory
class ColorThiefFromImage(ColorThief):
    def __init__(self, image):
        self.image = image

Creating a fork

I don't want to do this myself as I'm not too familiar with PyPi or exactly how this code works but someone with more experience should really make a fork where pull requests can actually get merged and issues fixed.

ImportError: cannot import name ColorThief

Though my install says

Requirement already satisfied: colorthief in /home/quinten/anaconda2/lib/python2.7/site-packages
Requirement already satisfied: Pillow in /home/quinten/anaconda2/lib/python2.7/site-packages (from colorthief)
Requirement already satisfied: olefile in /home/quinten/anaconda2/lib/python2.7/site-packages (from Pillow->colorthief)

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.