David Schmudde / Oct 10 2019
Remix of Python by Nextjournal

Color Palette Extractor

This article installs dependencies and establishes the basic functionality of color extraction from an image.

Install Dependencies

pip install --upgrade pip
pip install haishoku pillow

API

from haishoku.haishoku import Haishoku
from PIL import Image

def new_image(mode, size, color):
    return Image.new(mode, size, color)

path = 
Claude_Monet_-_Springtime_-_Google_Art_Project.jpg
# path = "https://upload.wikimedia.org/wikipedia/commons/d/dc/Yo_logo.png" # getPalette api palette = Haishoku.getPalette(path) # getDominant api # dominant = Haishoku.getDominant(path) # showPalette api # Haishoku.showPalette(path) # showDominant api dominantImage = Haishoku.showDominant(path) # Haishoku object h = Haishoku.loadHaishoku(path) dominantColor = new_image('RGB', (100, 100), h.dominant) dominantColor.save("/results/dominateColor.jpg", "JPEG")
dominateColor.jpg