This is a simple project to demonstrate the usage of unsupervised Machine Learning methods (clustering with scikit-learn KMeans) to extract colors from images.
Theres a Jupyter Notebook with a step by step explanation in this same repo: demo/Extract colors from images.ipynb
There's a simple API endpoint to use it as a service: /api/extract
. It accepts two different types of requests:
A JSON POST request with two parameters:
url
(mandatory): The URL of the picture to extract colors fromclusters
(optional): The number of clusters to use (default=6)
$ curl -X POST -d '{"url": "https://images.unsplash.com/photo-1536506591919-966afe6f7c09?fit=crop&w=750&q=80"}' -H "Content-Type: application/json" https://colors.rmotr.com/api/extract
A multipart/form-data
request with two form values:
file
(mandatory): The image file to extract colors fromclusters
(optional): The number of clusters to use (default=6)
$ curl -X POST -F "file=@demo/sample-image-1.jpg" -F "clusters=7" http://localhost:5000/api/extract
Frontend magic by:
Sample images from unsplash: