将RGBW颜色转换为标准RGB / HSB rappresentation [英] Converting an RGBW color to a standard RGB/HSB rappresentation

查看:890
本文介绍了将RGBW颜色转换为标准RGB / HSB rappresentation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在家庭自动化系统中建立了灯光管理界面。我设法控制标准的开/关和可调光灯的各种提供商有很少的问题,但现在我陷入了与RGB光相关的问题。

I am building an interface for light management in a home automation system. I managed to control standard on/off and dimmable light for various providers with little problem, but now I am stuck with a problem related to RGB light.

目前使用的是RGBW LED条 - 具体来说,我正在使用低成本的RGBW灯:灯是由四个LED组成,每个LED可以单独控制。
为了更清楚 - 我正在处理一些c#代码,应该检索当前选定的颜色并在UI中显示它,并使用户能够为光指定新的颜色。要设置颜色并检索它,我必须使用命令提供程序,使我能够通过Web服务发送和接收命令。

The light I am currently using is an RGBW led strip - specifically, I am working with a low-cost RGBW light: the light is composed by four led and every led can be controlled individually. To be more clear - I am working on some c# code that should retrieve the currently selected color and display it in the UI, and enable the user to specify a new color for the light. For setting the color and retrieving it I must use a command provider that enables me to send and receive commands via a web service.

提供程序使用RGBW颜色 - 四使用红色,绿色,蓝色和白色的组件。要在我的界面上表示当前的光颜色,我想将服务返回的RGBW颜色转换为更标准的RGB / HSB方案。

The provider works with RGBW colors - the four component for Red, Green, Blue and White are used. To represent the current light color on my interface I would like to translate the RGBW color returned by the service to a more standard RGB/HSB scheme.

搜索网页,只有参考的颜色转换,我发现(不包括rgb到rgbw转换的c ++示例,根据我的理解,必须有一些严重的错误)是这篇文章显示从HSI到RGBW的转换,这是我的需要:点击此处

Searching the web, the only reference for color conversion that I found (excluding a c++ sample for rgb to rgbw conversion that, based on my understanding, must have some severe bug) is this article that shows a conversion from HSI to RGBW, which is the inverse of what I needed : link here

我正在寻找一些关于如何实现这种转换的洞察(或简单解释为什么不可能)。只要我得到从RGB到RGBW的转换是任意的 - 单个RGB值可以表示为多个RGBW值,但相反的转换应该是明确的。还要注意,虽然我使用c#,请随时参考其他语言的算法太 - 语言不是问题,问题是,我不知道数学做颜色转换。

I am searching for some insight about how I can achieve this conversion (or a simple explanation of why it isn't possible). As far as I get the conversion from RGB to an RGBW is arbitrary - a single RGB value can be represented as multiple RGBW values, but the opposite conversion should be univocal. Also note that while I am using c#, feel free to refer to algorithms in other language too - language isn't the problem, the problem is that I don't know the math to do the color conversion.

推荐答案

如何将RGB转换为RGBW在以下文章的第2.1项中描述

How to convert RGB to RGBW is described in item 2.1 of the following paper

a href =http://www.mirlab.org/conference_papers/International_Conference/ICASSP%202014/papers/p1214-lee.pdf =nofollow> http://www.mirlab.org/conference_papers/International_Conference/ ICASSP%202014 / papers / p1214-lee.pdf

http://www.mirlab.org/conference_papers/International_Conference/ICASSP%202014/papers/p1214-lee.pdf

想想你的LED是一个巨大的像素。 Oliver的答案使用Wo = min(Ri,Gi,Bi),什么是计算便宜,只是工作。本文解释了最小化功耗的其他替代方案,有利于家庭自动化项目。我还在一个家庭自动化项目与OpenHAB,Arduino和RGBW LED,一方面纸提出的替代品将是好的,另一方面,一个巨大的LUT只是不工作,转换所有的价值观在arduino战斗机。
我建议你尝试使用不是这样的能量高效技术来校正RGB值:

Think of your leds as a huge pixel. Oliver's answer uses Wo = min(Ri,Gi,Bi), what is computationaly cheap and just works. This paper explains other alternatives to minimize power consumption, what is good for a home automation project. I'm also on a home automation project with OpenHAB, Arduino and RGBW leds and on the one hand paper proposed alternative would be good, on the other hand a huge LUT would just not work and convert all values on arduino eighter. I would suggest you to try correcting RGB values using not so energy eficient technics as cited in the paper:

假设Ri,Gi,Bi是颜色输入,从0到255的整数,因此Q = 255,输出为Wo,Ro,Go和Bo,值为0到255:

Assuming Ri, Gi, Bi are color inputs, integers from 0 to 255, so Q = 255 and that your outputs are Wo, Ro, Go and Bo with values from 0 to 255:

M = max(Ri,Gi,Bi)
m = min(Ri,Gi,Bi)

Wo = if (m/M < 0.5) use ( (m*M) / (M-m) ) else M 
Q = 255
K = (Wo + M) / m
Ro = floor( [ ( K * Ri ) - Wo ] / Q )
Go = floor( [ ( K * Gi ) - Wo ] / Q )
Bo = floor( [ ( K * Bi ) - Wo ] / Q )

在电子表格中进行练习,然后在Wo = m,m ^ 2和-m ^ 3 + m ^ 2 + m上进行实验,与正确的Qw,你会惊讶,没有校正的简单的解决方案不是一个人会期望和其他答案不变化那么多。检查纸张的颜色失真结果,我想如果你不正确的RGB值,你会得到一些洗出的颜色。

Exercise it in a spreadsheet before implementing, experiment on Wo = m, m^2 and -m^3+m^2+m, correct Wo value with the right Qw and you will be surprised that the simple solution without correction is not what one would expect and that other answers do not vary that much. Check the paper for color distortion results, I suppose that if you do not correct RGB values you will end up with some washed out colors.

这篇关于将RGBW颜色转换为标准RGB / HSB rappresentation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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