Given an RGB value what would be the best way to find the closest match in the database?

前端 未结 8 1587
别跟我提以往
别跟我提以往 2020-12-04 17:02

I have a rgb value and if it doesn\'t exist in the color table in my database I need to find the closest color. I was thinking of comparing all values and finding the diffe

8条回答
  •  Happy的楠姐
    2020-12-04 17:24

    One step better than average is nearest square root:

    ((delta red)^2 + (delta green)^2 + (delta blue)^2)^0.5
    

    This minimizes the distance in 3D color space.

    Since a root is strictly increasing, you can search for the maximum of the square instead. How you express this in SQL would depend on which RDBMS you're using.

提交回复
热议问题