如何将RGB颜色转换为最接近的匹配8位颜色? [英] How to convert an RGB color to the closest matching 8-bit color?
问题描述
我有一个应用程序可以对视频中显示的前16个颜色进行索引。
我试图编写另一个应用程序,允许用户选择颜色然后应用程序会找到该颜色出现的所有视频。
问题是,由于我每个视频只索引16种颜色,因此用户选择RGB颜色。
我想到了一种方法,我可以使这个工作 - 我可以索引
然后,当用户选择RGB颜色时,我可以将用户选择转换为相同的8位颜色
这种方式我总是有匹配。
现在是如何将RGB颜色转换为最接近的8位颜色?
要转换为网络安全调色板,您需要将每个r,g,b组件的范围从0-255转换为0-5并组合它们:
color =(r * 6/256)* 36 +(g * 6/256)* 6 +(b * 6/256)
I've an application that indexes the top 16 colors that appear in videos.
I'm trying to write another application that allows the user to select a color and then the application finds all videos that this color appears in.
The problem is that as I only index 16 colors per video, the users choose an RGB color. The probability that this color is indexed is very low, so almost always my application returns no results.
I thought of a way I could make this work - I could index the colors that appear in the video and convert them to closest 8-bit color.
Then when a user selects an RGB color, I could convert the user choice to the same 8-bit closest color.
This way I'd always have matches.
The only major problem I've right now is how to convert an RGB color to the closest 8 bit color?
解决方案To convert to the web-safe palette, you need to convert the range of each of the r,g,b components from 0-255 to 0-5 and combine them:
color = (r*6/256)*36 + (g*6/256)*6 + (b*6/256)
这篇关于如何将RGB颜色转换为最接近的匹配8位颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!