You did not understand anything, I am sorry!

When I find the solution I will explain to you.

If you share the problem context, we can more easily help you find a solution. This is an interesting question, but difficult to assist with in the abstract.

1 Like

If you reduce the number of colors, you will lose some faint colors.

You cannot have it both ways.

So you’re losing the Alpha channel?

Did you manage to get any solution?

Of course!

For the moment I arrived at that but I must deepen.

I proceed as follows:

- For each pixel of the image, we transform it into HSV. http://www.easyrgb.com/en/math.php
- With the value H we are already sure to have the right color.
- The problem is that for a too low value of saturation (S) the distance between the colors brings us back to white for example.

For any saturation value (S) close to 0 but not zero, it is reduced to 12.5%. - Then we convert the color of the pixel into XYZ and finally into LAB to calculate the distance between the colors (CIEDE2000) https://en.wikipedia.org/wiki/Color_difference

We retain the closest distance in the color palette and therefore the final color of the pixel.

It works for light colors but not for some grays, etc, you have to play on the “V” too I think.

I will continue to search.

Tim,

I’m not a specialist but I’m still on the 2010 version of Xojo and there we weren’t talking about the Alpha channel yet I think