This is part 1 of how to find the dominant colours within an image. You might spot this functionality around the internet, as it’s used to give images background colours before the image has loaded.
We use a package to do this – which manages much of the heavy lifting. The package, called prominentcolor, uses the Kmeans++ algorithm to work this out. By default, it will return us the three most popular colours after both cropping and resizing the image.