lmcinnes / umap

Uniform Manifold Approximation and Projection
BSD 3-Clause "New" or "Revised" License
7.39k stars 803 forks source link

[Documentation] Update RGBa parameter example to a perceptual colorspace like CIELab? #602

Open hmswaffles opened 3 years ago

hmswaffles commented 3 years ago

In the documentation about parameters, 4-dimensional RGBa color coordinates are visualized in 2D, and colored, to showcase how various UMAP parameters affect the final reduction. However, RGBa is not a perceptual color space, which means readers' intuitions about which points should be grouped together based on color similarity will be off.

One could instead convert the RGBa coordinates to CIELab (a perceptual colorspace). One way to do this is to go from RGBa to RGB, and then RGB to CIELab (a perceptual color space) via the color transformation functions found here: https://scikit-image.org/docs/dev/api/skimage.color.html. There might be other ways to do this conversion as well.

lmcinnes commented 3 years ago

It's a good idea. The original RGBA example was nice just because it was a simple to explain 4D space that people could still have some basic intuition for. I would be happy to look at a PR for the same walkthrough with CIELab or similar.

hmswaffles commented 3 years ago

So I've started working on this... Using CIELab coordinates results in UMAP reductions with more intuitive color <=> spatial differences (especially for the N=1 component image -- all of the points are nicely separated into colored bands.) On the other hand, CIELab is only a three-dimensional space, which means that the N=3 components reduction is moot.

lmcinnes commented 3 years ago

Perhaps you could interleave the two options, explaining why CIELab makes more sense, but use the RGBa where appropriate. The different metrics section at the end is also probably easier in straight RGBa. So perhaps there is a nice balance between the two?

hmswaffles commented 3 years ago

I think I've solved the problem another way due to the fact that CIELab is about color and alpha is about transparency. I can generate 4D coordinates where the first three are Lab coordinates, and the fourth is an alpha coordinate. Such 4d points can be run through UMap. Then for coloring I can convert the Lab coordinates to RGB, and combine them with the appropriate alpha coordinate... Voila, perceptual RGBa.

Colorspace purists (?) might balk, but the initial results look good.

lmcinnes commented 3 years ago

Color space purists will definitely balk more at the pure RGBa version.