算法为任何正整数转换为RGB值 [英] Algorithm to convert any positive integer to an RGB value

查看:423
本文介绍了算法为任何正整数转换为RGB值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有我们要显示热图。这将弥补正在显示的值的数目不详(但他们将是正整数)。数的范围也是未知(再次,所不同的是它们将posiitive integars)。该范围可以是介于0和200或578和1M或什么的。它依赖于数据,这是未知的。

We have a heatmap we want to display. The numbers that will make up the values being displayed are unknown (except that they will be positive integers). The range of numbers is also unknown (again, except that they will be posiitive integars). The range could be between 0 and 200 or 578 and 1M or whatever. It depends on the data, which is unknown.

我们要采取一个未知的范围正整数,并把它变成一个缩放(COM pressed)范围内,在热图的RGB值显示。我希望这是有道理的。 谢谢!

We want to take an unknown range of positive integers and turn it into a scaled (compressed) range to be displayed with RGB values in a heatmap. I hope this makes sense. Thanks!

我要澄清的是最小/最大值需要插入forumla。

I want to clarify that the min/max values need to be "plugged" into the forumla.

推荐答案

您需要先找到这些值的范围来获得的最小值和最大值。 然后,你需要创建一个色阶像下面这个图片吧。可以用不同的功能试验,以整数映射到一个RGB。你需要3职能R(X),G(X),B(X)。看下面的图片就loks像B(X)在中间的山峰,R(​​X),在年底高峰和绿色的是别的地方。只要你确保你永远不会得到两个(位RGB)用X,那么你有你的转换一定的价值。

You need to first find the range of those values to get the min and max. Then you need to create a colour scale like the bar below this image. You can experiment with different functions to map an integer to an RGB. You need 3 functions R(X), G(X), B(X). Looking at the image below it loks like B(X) peaks in the middle, R(X) peaks at the end and green is somewhere else. As long as you make sure that you never get two (RGBs) for some value of X then you've got your conversion.

编辑: 试想想它,你可以品尝各地的YUV空间中的一些单位圆。

Come to think of it you could sample some unit circle around YUV space.

甚至只是下载高分辨率的彩条,并品尝了。

Or even just download a high-res colour bar and sample that.

编辑2: 我只是面临着彩条的产生和记忆的MATLAB /八度彩条code。我绘制他们的数据,得到了下面的图像。

EDIT 2: I was just faced with color bar generation and remembered the MATLAB/Octave colorbar code. I plotted their data and got the following image.

这篇关于算法为任何正整数转换为RGB值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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