globocom/thumbor — pull request #157 by fabiomcosta (2013-02-05 23:23:26+00:00)
Title: Adding the "auto" option to the fill filter

Now its posible to pass "auto" as an option to the fill filter and it will choose a color that looks ok with the current image.

The implementation uses opencv's K-means implementation. I'm not really sure if it's the best option when you have only one cluster, but it's working fine.

http://docs.opencv.org/modules/core/doc/clustering.html

Also got the idea from this post:

http://charlesleifer.com/blog/using-python-and-k-means-to-find-the-dominant-colors-in-images/

So, credits for him.

Examples of the current implementation:
![](http://f.cl.ly/items/2e3e06111J2p1U0v1x2v/Image%202013.02.05%206:07:09%20PM.png)
![](http://f.cl.ly/items/3H2D0n242V1U1L0N0933/Image%202013.02.05%206:19:09%20PM.png)
![](http://f.cl.ly/items/450J261q3j0r2E1s3y1b/Image%202013.02.05%206:19:45%20PM.png)
![](http://f.cl.ly/items/3w01192M2g0j3H3I2q3n/Image%202013.02.05%206:20:04%20PM.png)
![](http://f.cl.ly/items/3S3c032p0c2l0x3Q1Q0z/Image%202013.02.05%206:20:26%20PM.png)