如何转换为RGB颜色最接近的匹配8-bit色彩? [英] How to convert an RGB color to the closest matching 8-bit color?

查看:216
本文介绍了如何转换为RGB颜色最接近的匹配8-bit色彩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,指数出现在影片的前16名的颜色。

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.

现在的问题是,当我只指数每部影片的16种颜色,用户选择一个RGB颜色。这个颜色索引的概率非常低,所以几乎总是我的应用程序不返回任何结果。

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.

我想了个办法,我可以做这项工作 - 我能指标显示在视频并将其转换为最接近的8位色的颜色

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.

然后,当用户选择一个RGB颜色,我可以转换的用户选择相同的8位最接近的颜色。

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.

唯一的主要的问题我有现在的问题是如何将RGB颜色转换为最接近的8位色?

The only major problem I've right now is how to convert an RGB color to the closest 8 bit color?

推荐答案

您需要做的是转换RGB到HSB(色相饱和度亮度)值。 HSB是3个字节,就像RGB,所不同的是HSB值可以更容易地比RGB比较

What you need to do is convert the RGB to an HSB (hue saturation brightness) value. HSB is 3 bytes, just like RGB, the difference is that HSB values can be compared much more easily than RGB.

您的下一个步骤是决定一个重要的权重。例如,如果你关心的是颜色/色相,而不是饱和度或亮度,那么你就可以扔掉S和B字节,只是使用的颜色字节。

Your next step is decide on an "importance" weighting. For example, if all you care about is "color/hue", not saturation or brightness, then you can throw away the S and B bytes and just use the color byte.

如果它是我和我被限制为8比特,我会用4位的颜色信息(16种不同的颜色),3位的饱和的(8个不同的值),和1比特的亮度信息(亮或暗)。

If it were me and I were constrained to 8 bits I would use 4 bits of color information (16 different colors), 3 bits of saturation (8 different values), and 1 bit of brightness information (light or dark).

本文介绍了如何做HSB在Java中:

This article describes how to do HSB in Java:

http://java.sys-con.com/node/43559

该人士$ ​​C $ C对这篇文章有一个RGB到HSB转换器的Java。

The source code for this article has an RGB to HSB converter in Java.

这篇关于如何转换为RGB颜色最接近的匹配8-bit色彩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆