# How to properly color clusters for visualization

I've some data that I can express as an image. Within this data I found some clusters (shown in the image below). I can just assign different colors to different clusters and visualize the image but if I do so randomly I lose the spatial relation that can be observed within the image.

To solve that in order to let close clusters have close colors I thought that a good solution might be to map this space into a color map (or the other way around)

Just to say I guess that I should use the color map such that in the center is black rather than white just for displaying purposes. (white marker in white canvas does not show up much ;) )

A possible solution is to directly map the PCA of my centroids to 3D coordinate system and use this one to map HSV coloration.

Centroids nearby have similar coloration but differences in saturation and brightness does that nearby differ and are close to other centroids far away in the first two coordinates but close in the third one.

A solution is to use the same coordinate for saturation and brightness leading to this coloration (or even just use hue)

However clusters on the top can be easily differentiated meanwhile the clusters on the bottom they all look similar (dark). On the other hand using only hue it would lead to a reduced subset of colors. Saturation can be mapped as distance to the center but still, the color space is not properly used to have the best coloration.

The final goal is to re-project back into an image the coloration of the clusters to obtain a colored visualization of its texture, as follows:

## migrated from math.stackexchange.comSep 3 '13 at 13:11

This question came from our site for people studying math at any level and professionals in related fields.

• please try to post the same question on stackoverflow or cross-validated. – Avitus Sep 3 '13 at 12:42
• Ditto what Avitus said. This isn't a question about mathematics. You'll have better luck at cross-validated, where people think about data visualization. – rschwieb Sep 3 '13 at 13:04
• Colours are fine, but why not use different symbols as well or instead? Different symbols e.g. $\diamond \circ +$ express qualitative contrasts well. On colour, remember that many people have difficulties distinguishing colours, especially red and green. – Nick Cox Sep 3 '13 at 13:50
• The idea is to be able to then use those colors to generate an image. Such clusters represent textures of my image, and i want to color every texture with a color. I can just do it randomly but the images look disturbing, and the sense of close and far texture gets lost. – Sik Sep 3 '13 at 13:54
• The question looks to be about colour visualization of densities, or clots, and not about clusters. Clusters are descrete classes, although some speak of 'overlapping' clusters as well. But in any case clusters cannot flow gradually into each other, as your fine coloration implies. Was the question ill-formulated? – ttnphns Sep 3 '13 at 14:40

First of all, I don't see any meaningful clusters here. This looks like a forced quantization to me (typical for k-means) - the results may be all but meaningful.

Have you considered just using 1D or 2D projections, e.g. by doing multidimensional scaling? You might be aware that in HSV space, we can't really tell apart different hues, unless they are also well saturated and bright enough. So you might want to use a 2D projection to maximum saturation, and then use only values 0.5 to 1.0, plus the whole range of hues.

However, for HSV space, you'd need to project your data to a cone formed space, actually... RGB may be the better choice, because the axes may be more uniformly on what we can visually tell appart.

You may want to look at discussions such as this:

https://gamedev.stackexchange.com/questions/46463/is-there-an-optimum-set-of-colors-for-10-players

which focus on finding a good, user-friendly "colorful" palette. Don't neglect that you also need contrast to the background (or in computer games: to the landscape)

• Well, that's actually what i did I extracted features from my image (actually i used SIFT) and then k-means to find 36 clusters to discretize the feature space. I'm preparing an illustrative example of how to characterize texture using SIFT and Bag-of-Words. 36 clusters is big enough and let us keep track of it. I was looking to colorize the SIFT image. Do you have any suggestion in order to cluster the space instead of using k-means? some mode-seeker methodology would be preferred? I've seen k-means be widely used for this application. – Sik Sep 3 '13 at 18:51
• The vectors should be sparse. I suggest you choose a fixed palette of 10 well-discernible colors, and assign them to the top 10 words for the image, and hide all the rare labels. If the resulting vectors are not sparse, the bag-of-words approach already failed. – Anony-Mousse Sep 3 '13 at 21:07