Finding nearest RGB colour

前端 未结 3 576
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-01 03:12

I was told to use distance formula to find if the color matches the other one so I have,

struct RGB_SPACE
{
    float R, G, B;
};

RGB_SPACE p = (255, 164, 3         


        
3条回答
  •  梦谈多话
    2021-01-01 04:15

    Note that the maximum possible distance is between (255, 255, 255) and (0, 0, 0), which are at a distance of 3 * 255^2. Obviously these two colours match the least (0% match) and they are a distance 100% apart. Then at least a 25% match means a distance less than 75%, i.e. 3 / 4 * 3 * 255^2 = 9 / 4 * 255 * 255. So you could just check if:

    distance <= 9 / 4 * 255 * 255
    

提交回复
热议问题