# How does DominantColors work?

I'm trying to understand the algorithms behind DominantColors[]. Unfortunately Trace[] and PrintTrace[] don't help. For example, running the PrintTrace below will crash Mathematica:

(Don't run to the following code)

img = ExampleData[{"TestImage", "Lena"}];
PrintTrace @ DominantColors[img]


And the same for Trace:

Going the other way, I then tried using GeneralUtilities's PrintDefinitions[] function. But this really doesn't help much either as there is an huge amount of indirection, involving many undocumented functions including:

ImageColorOperationsDumpiDominantColors
ImageColorOperationsDumpoldDominantColors
ImageColorOperationsDumpmergeColorClustersUtil
ImageColorOperationsDumpestimateClusterStrengh
ImageColorOperationsDumpgetNeighbours
ImageUtilitiesgetMask
ImageTransformPixelCoordinates
ImageSegmentationDumpiClusteringComponents


Any other suggestions?

• Have you tried clicking on those functions in the PrintDefinitions window? Or directly running PrintDefinitions on them? – Batracos Mar 7 '18 at 15:43
• @Batracos yes but it is very confusing! I tired to pull out all the necessary definitions into a single notebook in order to step through the code, but there are too many deep roots! – M.R. Mar 8 '18 at 2:46
• Probably you can use TraceToFile from this question. – rhermans Jun 18 '18 at 21:48
• What is PrintTrace`? – Chip Hurst Sep 1 '18 at 17:01