A visual representation of the k-means algorithm applied to images downloaded asynchronously.
Every pixel RGB value is extracted and transformed to a CIELAB space. All pixels in an image are averaged into a single color vector which is used to run the K-means algorithm and cluster images in this space. Notice in the demo how it clusters images in tiles ordered vertically. Also notice that K-means is not always perfect, it might get stuck in a local minima resulting in an aparent disorder.
With this approach this algorithm will only work properly with images that have a single comon color. A better approach will be implemented in the future.
Get top 5 colors and run the algorithm in a more sensible representation of the image with a model of these five colors.
A list of image links is provided in json format for download. It can be easily modified to append or change them. In the future user inputs will be configured to add new images in-app. Warning: this app is intended for dev purposes only and the GRID_SIZE
variable is tightly coupled to the number of images in that list and the validity of their links, so make sure that provided links are valid and GRID_SIZE >= urlList.count
.
Also a small python script is provided for easier integration with image net. Just search and download a synset, save it with the name urls.txt
in the same directory of setup.py
and run it. Then copy the resulting json into the xCode project.
Based on ideas from:
- Swift Algorithm Club
- DominantColor by indragiek
- Bernardo Santana
- @bsantanas
- bsantanas.wordpress.com