A few weekends ago, I wanted to brush up on my clustering techniques. I recall —from an image processing class back in college — that you can reduce the number of unique colors in an image down to a few colors while keeping the important ones. This is achieved by doing k-means clustering on the RGB values of the pixels in an image. The number of colors that you want in your reduced palette is the k value in k-means clustering; in other words the number of cluster centers in RGB space that your image inhabit.
This was particularly useful in the old days of video game graphics if an image needed to be rendered in a device with limited memory. By reducing the palette, you can conform to the limited color palette of PAL or SECAM, etc. since only 8 bits or 16 bits are allocated to the entire color palette (in contrast to the 24-bit RGB that is ubiquitous now). Today’s use? Well, if you’re particularly nostalgic about the artistry of low-bit graphics or building something to display on a LED matrix, this could be the use case.
While playing around, I casually thought: “what if we transferred the reduced palette of one image into another?” It’s a seemingly innocuous question that expanded my knowledge of colors and parallel-processing toolbox. In this article, I’m going to explain how this artificial task of palette transfer can be done and how to take it further. Get ready to use tools from numpy, scikit-learn and dask. Look for the code on a prepared Colab notebook containing everything explained in this article.

#algorithms #scikit-learn #dask #colors #numpy

The Perils of Palette Transfer
1.15 GEEK