The API takes an image URL as a parameter and will use K-Means to generate a palette.Īdditionally, I found that the website Coolors makes it easy to create a color palette URL, so the API can return the color palette as a 2D array of colors or as a URL to a Coolors palette. import numpy as np import image def palette (img): ''' return palette in descending order of frequency ''' arr np.asarray (img) palette, index np.unique (asvoid (arr).ravel (), returninversetrue) palette palette.view (arr.dtype).reshape (-1, arr. Flask AppĪs a final bonus, I decided to create a simple proof-of-concept API for generating color palettes from images. DBSCAN), and adjusting the color distance metric (If you’re interested, you can read more about color differences here). Agglomerative clustering + HSV colors), hyper-parameter tuning, using different algorithms (e.g. Then just copy the HEX codes from the color palette app with a simple. In order to further improve the results, some options include combining techniques (i.e. This simple color palette generator extracts colors from any photo or file on upload. As you can see, the HSV approach includes both the blue and the yellow (though still no red). The above image shows palettes generated for the same image using K-Means clustering with RGB colors and HSV colors. Supports images that are present in the DOM, as well as (external) URLs. RGB represents a color as a combination of the intensities of the red, green, and blue channels while HSV represents a color as the hue (the spectrum of base colors), saturation (the intensity of a color), and value (the relative lightness or darkness of a color) - which you can read more about here. Works in the browser and in hybrid environments like Electron. Still from Only God Forgives (2013), courtesy of FILMGRAB, with k-means RGB and HSV generated palettes.Īnother approach is to convert the image’s colors from RGB to HSV.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |