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

前端 未结 8 1579
别跟我提以往
别跟我提以往 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条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 17:32

    Comparing a color sample to the whole color list every time is probably not optimal. This can be optimized by putting the colors in the color list into a search tree. If you are comparing the color sample on its Red, Green and Blue (RGB) value, you would put the colors in the color list into a three dimensional search tree. The search tree could be created once and saved to a (json, xml) file or in a database. This may be worth it if speed is important, e.g. there are many points to compare.

    • Use a [k-d tree] with the R, G and B values 0-256 as X, Y, and Z coordinates1.
    • Or another type of nearest neighbour search.

提交回复
热议问题