indragiek / DominantColor

Finding dominant colors of an image using k-means clustering
MIT License
960 stars 93 forks source link

Are results meant to be stable? #36

Closed coolya closed 7 years ago

coolya commented 7 years ago

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]
indragiek commented 7 years ago

This is expected, there is randomization involved in k-means clustering. See here: https://github.com/indragiek/DominantColor/blob/master/DominantColor/Shared/KMeans.swift#L41