indragiek / dominantcolor Goto Github PK
View Code? Open in Web Editor NEWFinding dominant colors of an image using k-means clustering
License: MIT License
Finding dominant colors of an image using k-means clustering
License: MIT License
For the same image, using -Os
optimization level:
Unmemoized
n = 100 averaged 4 ms
n = 1000 averaged 39 ms
n = 2000 averaged 81 ms
n = 5000 averaged 202 ms
n = 10000 averaged 416 ms
Memoized
n = 100 averaged 8 ms
n = 1000 averaged 68 ms
n = 2000 averaged 133 ms
n = 5000 averaged 318 ms
n = 10000 averaged 639 ms
Roughly twice as slow with memoization.
please update to swift2.0 for Xcode 7.0,thanks
k-means++ might be better than choosing all of the centroids randomly.
First of all, Thank you for your nice work! Awesome.
But in general case, library users finally needs only 1~2 color groups like primary, secondary or background(outbound) colors. Currently the result seems that in each 2 items are pretty similar. Also in this example https://github.com/indragiek/DominantColor/raw/master/mac.png, I think first color is not dominant color, it may be secondary or background with the last color.
Currently you did perform it by "size" like following.
// Sort the clusters by size in descending order so that the
// most dominant colors come first.
clusters.sortInPlace { $0.size > $1.size }
Are you have some plans to improve? Or, please let me know some hints or important parts of your lib.
Thanks.
I'm using your code in my Swift 3 app and it works fine in the simulator but when I try to run it on my 7 Plus device, it doesn't compile, complaining that value of UIImage has no member dominantColors
.
The weird thing is running your project as a stand-alone works fine on my device.
Xcode does see the DominantColor framework when I try to import it using import DominantColor
, so I'm really at a lost.
Any clues?
iOS app for testing the algorithm.
Any fix for this issue?
Faster performance with the tradeoff of accuracy.
There are a number of different methods listed here
Framework targets for iOS and Mac for the reusable parts of the project.
Could you add a Podspec? I can help if you want and submit a PR.
Might be able to make it perform a little better by memoizing the results of RGB <-> LAB conversions and the CIE 2000 color diff algorithm.
I have own implementation for CIE76 and CIE2000.
For 5,000 samples, it take 10times than CIE76 in my computer.
Does CIE2000 is expensive calculation? I am not sure that i make correctly or not.
Plz someone comment this issue!
Lab color space seems like it would be more accurate if we could find a way to do the conversion from RGB.
I don't know how to use DominantColor in my project, I dragged the shared folder into my project but that doesn't work. Can you tell me how to use it?
Is there a way to know which pixel or area in the image corresponding to the dominant colors?
Accounting to http://www.easyrgb.com/en/math.php#text15, d65 tristimulus x is 95.047, but in the code the num is 5.047, is it right?
My understanding is the OpenGL is being deprecated next year. Will this be affected as it uses GLKit?
Some numbers from the existing Swift implementation:
n = 100 averaged 4 ms
n = 1000 averaged 39 ms
n = 2000 averaged 74 ms
n = 5000 averaged 187 ms
n = 10000 averaged 384 ms
(2.3GHz i7, 2012 rMBP)
Extensions to UIImage
on iOS and NSImage
on Mac to make it easier to use without having to manually create a CGImage
.
That will be amazing.
When I sample the same image multiple times I get very different results:
Something like:
let c1 = image.dominantColors()
let c2 = image.dominantColors()
let c3 = image.dominantColors()
print(c1)
print(c2)
print(c3)
Results in quite different colors:
[NSCustomColorSpace Device RGB colorspace 0.601163 0.451928 0.29805 1, NSCustomColorSpace Device RGB colorspace 0.167657 0.346547 0.366693 1, NSCustomColorSpace Device RGB colorspace 0.932639 0.899493 0.844565 1, NSCustomColorSpace Device RGB colorspace 0.300963 0.190313 0.13295 1, NSCustomColorSpace Device RGB colorspace 0.209064 0.370543 0.368402 1, NSCustomColorSpace Device RGB colorspace 0.959817 0.783332 0.505265 1, NSCustomColorSpace Device RGB colorspace 0.866478 0.734177 0.559615 1, NSCustomColorSpace Device RGB colorspace 0.80283 0.586079 0.331463 1, NSCustomColorSpace Device RGB colorspace 0.145703 0.320739 0.346772 1, NSCustomColorSpace Device RGB colorspace 0.221972 0.415689 0.443135 1, NSCustomColorSpace Device RGB colorspace 0.737809 0.513082 0.260469 1, NSCustomColorSpace Device RGB colorspace 0.281155 0.455335 0.465255 1, NSCustomColorSpace Device RGB colorspace 0.221931 0.405273 0.408174 1, NSCustomColorSpace Device RGB colorspace 0.21869 0.409611 0.429996 1, NSCustomColorSpace Device RGB colorspace 0.234584 0.400131 0.392035 1, NSCustomColorSpace Device RGB colorspace 0.21333 0.391863 0.38884 1]
[NSCustomColorSpace Device RGB colorspace 0.179195 0.35601 0.368129 1, NSCustomColorSpace Device RGB colorspace 0.221092 0.394226 0.392182 1, NSCustomColorSpace Device RGB colorspace 0.731796 0.527369 0.303106 1, NSCustomColorSpace Device RGB colorspace 0.900029 0.709735 0.447639 1, NSCustomColorSpace Device RGB colorspace 0.899187 0.828078 0.731685 1, NSCustomColorSpace Device RGB colorspace 0.981269 0.937817 0.851738 1, NSCustomColorSpace Device RGB colorspace 0.563752 0.426373 0.29075 1, NSCustomColorSpace Device RGB colorspace 0.380421 0.251262 0.160972 1, NSCustomColorSpace Device RGB colorspace 0.144352 0.32968 0.356929 1, NSCustomColorSpace Device RGB colorspace 0.243707 0.430158 0.451196 1, NSCustomColorSpace Device RGB colorspace 0.587503 0.488635 0.360218 1, NSCustomColorSpace Device RGB colorspace 0.159995 0.325696 0.34995 1, NSCustomColorSpace Device RGB colorspace 0.2791 0.162244 0.11213 1, NSCustomColorSpace Device RGB colorspace 0.215359 0.141883 0.117462 1, NSCustomColorSpace Device RGB colorspace 0.21733 0.40994 0.436859 1, NSCustomColorSpace Device RGB colorspace 0.141187 0.325496 0.352944 1]
[NSCustomColorSpace Device RGB colorspace 0.220951 0.405691 0.415336 1, NSCustomColorSpace Device RGB colorspace 0.169029 0.349393 0.370444 1, NSCustomColorSpace Device RGB colorspace 0.927746 0.764487 0.524068 1, NSCustomColorSpace Device RGB colorspace 0.938916 0.901397 0.843266 1, NSCustomColorSpace Device RGB colorspace 0.162621 0.338714 0.355336 1, NSCustomColorSpace Device RGB colorspace 0.289514 0.169255 0.111449 1, NSCustomColorSpace Device RGB colorspace 0.530895 0.42339 0.305094 1, NSCustomColorSpace Device RGB colorspace 0.645131 0.485872 0.323021 1, NSCustomColorSpace Device RGB colorspace 0.725126 0.511703 0.278788 1, NSCustomColorSpace Device RGB colorspace 0.812128 0.594165 0.335176 1, NSCustomColorSpace Device RGB colorspace 0.198869 0.375221 0.376283 1, NSCustomColorSpace Device RGB colorspace 0.260764 0.208588 0.180555 1, NSCustomColorSpace Device RGB colorspace 0.412618 0.265703 0.16161 1, NSCustomColorSpace Device RGB colorspace 0.51031 0.32944 0.17197 1, NSCustomColorSpace Device RGB colorspace 0.583589 0.607618 0.549271 1, NSCustomColorSpace Device RGB colorspace 0.289885 0.460979 0.465333 1]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.