<commit_before>## DominantColor

Finding the dominant colors of an image using the YUV color space and the k-means clustering algorithm.

### Algorithm

#### Color Space

The RGB color space does not take human perception into account, so the CIELAB color space is used instead, which is designed to approximate human vision <sup>[[1]](http://en.wikipedia.org/wiki/Lab_color_space#Advantages)</sup>. 

##### Conversion from RGB

The conversion from RGB values to LAB values requires first transforming the RGB values to an absolute color space like sRGB<sup>[[2]](http://en.wikipedia.org/wiki/Lab_color_space#RGB_and_CMYK_conversions)</sup>. On iOS, this conversion is not necessary because sRGB is the native device color space<sup>[[3]](https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGColorSpace/index.html)</sup>. On OS X, the conversion can be performed using [`-[NSColorSpace sRGBColorSpace]`](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSColorSpace_Class/index.html).

Once the colors have been converted to sRGB, they are first converted to linear sRGB values and then to CIE XYZ values<sup>[[4]](http://en.wikipedia.org/wiki/SRGB#The_forward_transformation_.28CIE_xyY_or_CIE_XYZ_to_sRGB.29)</sup>. Finally, they are converted to the CIE LAB color space<sup>[[5]](http://en.wikipedia.org/wiki/Lab_color_space#CIELAB-CIEXYZ_conversions)</sup> using a D65 standard illuminant<sup>[[6]](http://en.wikipedia.org/wiki/Illuminant_D65)[[7]](http://www.easyrgb.com/index.php?X=MATH&H=15#text15)</sup>. 

#### Color Difference

A simple calculation of the color difference simply takes the Euclidian distance between two vectors of LAB color coordinates<sup>[[8]](http://en.wikipedia.org/wiki/Color_difference#CIE76)</sup>. However, this does not address perceptual uniformity issues. This project uses the CIE 2000 definition of color difference instead, which adds several corrections to resolve these issues<sup>[[9]](http://en.wikipedia.org/wiki/Color_difference#CIEDE2000)</sup>. 

#### Clustering (k-means)

Pixels are grouped into clusters of dominant colors using a standard k-means clustering algorithm<sup>[[10](http://en.wikipedia.org/wiki/K-means_clustering)][[11](http://users.eecs.northwestern.edu/~wkliao/Kmeans/)][[12](http://cs.smu.ca/~r_zhang/code/kmeans.c)]</sup>. 

##### Choosing K<commit_msg>Remove reference to YUV in the README<commit_after>## DominantColor

Finding the dominant colors of an image using the CIE LAB color space and the k-means clustering algorithm.

### Algorithm

#### Color Space

The RGB color space does not take human perception into account, so the CIELAB color space is used instead, which is designed to approximate human vision <sup>[[1]](http://en.wikipedia.org/wiki/Lab_color_space#Advantages)</sup>. 

##### Conversion from RGB

The conversion from RGB values to LAB values requires first transforming the RGB values to an absolute color space like sRGB<sup>[[2]](http://en.wikipedia.org/wiki/Lab_color_space#RGB_and_CMYK_conversions)</sup>. On iOS, this conversion is not necessary because sRGB is the native device color space<sup>[[3]](https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGColorSpace/index.html)</sup>. On OS X, the conversion can be performed using [`-[NSColorSpace sRGBColorSpace]`](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSColorSpace_Class/index.html).

Once the colors have been converted to sRGB, they are first converted to linear sRGB values and then to CIE XYZ values<sup>[[4]](http://en.wikipedia.org/wiki/SRGB#The_forward_transformation_.28CIE_xyY_or_CIE_XYZ_to_sRGB.29)</sup>. Finally, they are converted to the CIE LAB color space<sup>[[5]](http://en.wikipedia.org/wiki/Lab_color_space#CIELAB-CIEXYZ_conversions)</sup> using a D65 standard illuminant<sup>[[6]](http://en.wikipedia.org/wiki/Illuminant_D65)[[7]](http://www.easyrgb.com/index.php?X=MATH&H=15#text15)</sup>. 

#### Color Difference

A simple calculation of the color difference simply takes the Euclidian distance between two vectors of LAB color coordinates<sup>[[8]](http://en.wikipedia.org/wiki/Color_difference#CIE76)</sup>. However, this does not address perceptual uniformity issues. This project uses the CIE 2000 definition of color difference instead, which adds several corrections to resolve these issues<sup>[[9]](http://en.wikipedia.org/wiki/Color_difference#CIEDE2000)</sup>. 

#### Clustering (k-means)

Pixels are grouped into clusters of dominant colors using a standard k-means clustering algorithm<sup>[[10](http://en.wikipedia.org/wiki/K-means_clustering)][[11](http://users.eecs.northwestern.edu/~wkliao/Kmeans/)][[12](http://cs.smu.ca/~r_zhang/code/kmeans.c)]</sup>. 

##### Choosing K
{'fraction_non_alphanumeric': 0.12697095435684647, 'fraction_numerical': 0.015352697095435684, 'mean_word_length': 5.867521367521367, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4272893', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1409, 'n_words': 410}