Octree color quantization
Imagine an Octree as a XYZ axes plot in 3D space. We can insert a RGB color by using each the red, green, and blue channels as its coordinates.
Then we pick the smallest possible sub-cube that contains the number of colors specified in the quantization function.