This question may be more to do with human psychology
I am trying to make a program that recreates a bit map image using a limited colour palette. I naively thought that I could simply find the squared difference of the Red/Green/Blue values and use that to quantify the squared difference between colours. However in practice this doesn't seem to work very well, shades of red are being matched to shades of purple and so on.
Does anyone have any suggestions of alternate comparison methods I could use?
int squaredDistance(colour a, colour b)
{
return (a.r - b.r)*(a.r - b.r) + (a.g - b.g)*(a.g - b.g) + (a.b - b.b)*(a.r - b.b);
}
int findClosestColour(colour a) //Returns id of colour that most closely matches
{
int smallestColourDistance = 195075;
int colourId = -1;
for(int i=0; i<NUMOFCOLOURS; i++)
{
if( squaredDistance(a, coloursById[i]) < smallestColourDistance)
{
smallestColourDistance = squaredDistance(a, coloursById[i]);
colourId = i;
if(smallestColourDistance == 0)
break;
}
}
return colourId;
}