lancegin / haishoku Goto Github PK
View Code? Open in Web Editor NEWA development tool for grabbing the dominant color or representative color palette from an image
License: MIT License
A development tool for grabbing the dominant color or representative color palette from an image
License: MIT License
Another Python library provides the same functionality: colorthief.
However both libs do not return the same palette:
The first line of colored circles is the palette from colorthief
, the second line is the palette from haishoku
.
Why do they differ so much?
( Source image: doom slayer by tis1451 - CC BY-SA 3.0 )
Feature request: Add header parameter when using remote url
Hi.
Currently haishoku
always returns a palette with max 8 colors:
cf. haishoku/haishoku.py on line 77
Could it be possible to make this configurable, to generate 16-colors palette for example, please?
Dear LanceGin,
Thank you for your wonderful work. I want to know if there is a way to input numpy array or PIL.Image rather than img_path? I already preprocess my images, I dont want to save one image to jpg then reload it.
Best Wishes,
Alex
from haishoku.haishoku import Haishoku
palette = Haishoku.getPalette( some_gif_image )
palette = Haishoku.getPalette(image_path)
File "/usr/lib/python3.7/site-packages/haishoku/haishoku.py", line 129, in getPalette
colors_mean = Haishoku.getColorsMean(image_path)
File "/usr/lib/python3.7/site-packages/haishoku/haishoku.py", line 65, in getColorsMean
grouped_image_colors = alg.group_by_accuracy(sorted_image_colors)
File "/usr/lib/python3.7/site-packages/haishoku/alg.py", line 54, in group_by_accuracy
rgb_maximum_json = rgb_maximum(sorted_tuple)
File "/usr/lib/python3.7/site-packages/haishoku/alg.py", line 23, in rgb_maximum
r_sorted_tuple = sorted(colors_tuple, key=lambda x:x[1][0])
File "/usr/lib/python3.7/site-packages/haishoku/alg.py", line 23, in <lambda>
r_sorted_tuple = sorted(colors_tuple, key=lambda x:x[1][0])
TypeError: 'int' object is not subscriptable
also just a sidenote, from haishoku.haishoku import Haishoku
looks quite awkward, you could import Haishoku
in __init__.py
, so it can be used as from haishoku import Haishoku
This is a cool idea. Are you interested in taking any pull requests? I've reworked the haishoku class so it's a bit more object-oriented by having methods on instances rather than on the type itself.
这个列表的所有图片都会出现错误,全部是黑白图片,但似乎不是所有黑白图片都会出现问题
All the pictures in this list will have errors, all black and white pictures, but it seems that not all black and white pictures will have problems.
image_list = ["https://store.playstation.com/store/api/chihiro/00_09_000/container/HK/ch/999/HP9000-CUSA02417_00-GONETOTHERAPTURE/1561603730000/image?w=432&h=432", "https://store.playstation.com/store/api/chihiro/00_09_000/container/HK/ch/999/EP4034-CUSA03094_00-ASIA000000000000/1555304545000/image?w=432&h=432", "https://store.playstation.com/store/api/chihiro/00_09_000/container/HK/ch/999/UP1164-CUSA13422_00-ASIA000000000000/1554792500000/image?w=432&h=432", "https://store.playstation.com/store/api/chihiro/00_09_000/container/HK/ch/999/UP9000-CUSA00695_00-ASIAFULLGAME0000/1561601024000/image?w=432&h=432", "https://store.playstation.com/store/api/chihiro/00_09_000/container/HK/ch/999/HP9000-CUSA12613_00-DEATHSTRAND00001/1561107092000/image?w=432&h=432", "https://store.playstation.com/store/api/chihiro/00_09_000/container/HK/ch/999/HP2005-CUSA14358_00-PATOBOXASIA00000/1560504014000/image?w=432&h=432"]
Traceback (most recent call last):
File "/Users/Phishion/Desktop/Haishokutest.py", line 12, in
dominant = Haishoku.getDominant(value)
File "/usr/local/lib/python3.7/site-packages/haishoku/haishoku.py", line 119, in getDominant
colors_mean = Haishoku.getColorsMean(image_path)
File "/usr/local/lib/python3.7/site-packages/haishoku/haishoku.py", line 65, in getColorsMean
grouped_image_colors = alg.group_by_accuracy(sorted_image_colors)
File "/usr/local/lib/python3.7/site-packages/haishoku/alg.py", line 54, in group_by_accuracy
rgb_maximum_json = rgb_maximum(sorted_tuple)
File "/usr/local/lib/python3.7/site-packages/haishoku/alg.py", line 23, in rgb_maximum
r_sorted_tuple = sorted(colors_tuple, key=lambda x:x[1][0])
File "/usr/local/lib/python3.7/site-packages/haishoku/alg.py", line 23, in
r_sorted_tuple = sorted(colors_tuple, key=lambda x:x[1][0])
TypeError: 'int' object is not subscriptable
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.