简体   繁体   English

指定有序值的RGB调色板

[英]RGB palette designated for ordered values

I have a function f(x,y), mostly monotonic, which produces some values in the range {0.0 .. 100.0}. 我有一个函数f(x,y),大部分是单调的,它会生成一些介于{0.0 .. 100.0}范围内的值。 I would like to draw them using different colors as a 2D picture, where (x,y) are coordinates and where distinctive colors stand for distinctive values of the function. 我想使用不同的颜色绘制它们作为2D图片,其中(x,y)是坐标,而独特的颜色代表函数的独特值。 The problem is following: I don't know how to map the values of this function to RGB color space preserving the order (visibly). 问题如下:我不知道如何将此函数的值映射到RGB色彩空间(保留顺序)。 I have found that smth. 我发现了那个。 like: 喜欢:

R = f(x,y) * 10.0f;
G = f(x,y) * 20.0f;
B = f(x,y) * 30.0f;
color = B<<16|G<<8|R; //@low-endian

works fine, but the resulting picture is too dark. 工作正常,但生成的图片太暗。 If I increase these constants, it makes things not better, because at some moment a color component will be greater than 0xFF, so it will overflow (one color component should be in the range {0 .. 0xFF}. 如果我增加这些常数,将使情况变得更好,因为有时某个颜色分量会大于0xFF,所以它将溢出(一个颜色分量应在{0 .. 0xFF}范围内。

Do you have any idea how to map values from {0.0 .. 100.0} to 您是否知道如何将值从{0.0 .. 100.0}映射到
RGB=[{0 .. 0xFF}<<16|{0 .. 0xFF}<<8|{0 .. 0xFF}] so that the resulting RGB values are visibly Ok? RGB = [{{0 .. 0xFF} << 16 | {0 ..0xFF} << 8 | {0 .. 0xFF}]],这样得到的RGB值显然可以吗?

PS: maybe you know, where to find more info about related theory online? PS:也许您知道,在哪里可以找到有关相关理论的更多信息? I remember only Comp.Graphics by Foley/Van Dam, but I don't have this book. 我只记得Foley / Van Dam撰写的Comp.Graphics,但我没有这本书。

UPDATE: I am looking for how to generate a chroma palette like one on the right: 更新:我正在寻找如何生成像右边一样的色度调色板: 在此处输入图片说明

You could just try clamping the values to a maximum of 255 (0xff). 您可以尝试将值限制为最大255(0xff)。

R = min((int)(f(x,y) * 10.0f), 0xff);
G = min((int)(f(x,y) * 20.0f), 0xff);
B = min((int)(f(x,y) * 30.0f), 0xff);

Edit: There are a lot of different ways to convert to colors automatically, but you might find that none of them generates the exact progression you're looking for. 编辑:有许多不同的方法可以自动将颜色自动转换为颜色,但是您可能会发现它们都无法生成所需的确切级数。 Since you already have a picture of an acceptable palette, one method would be to create a lookup table of 256 colors. 由于您已经具有可接受调色板的图片,因此一种方法是创建256色的查找表。

#define RGB(R,G,B) (B<<16|G<<8|R)

int palette[256] = { RGB(0,0,0), RGB(0,0,128), ... };

int greyscale = (int)(f(x,y) * 2.559999);
assert(greyscale >= 0 && greyscale <= 255);
int rgb = palette[greyscale];

If the lookup table is too much trouble, you could also break the greyscale range into different subranges and do a linear interpolation between the endpoints of each range. 如果查找表有太多麻烦,您还可以将灰度范围分为不同的子范围,并在每个范围的端点之间进行线性插值。

int interpolate(int from, int to, double ratio)
{
    return from + (int)((to - from) * ratio); 
}
if (greyscale <= 48)
{
    R = 0;
    G = 0;
    B = interpolate(0, 255, greyscale/48.0);
}
else if (greyscale <= 96)
{
    R = 0;
    G = interpolate(0, 255, (greyscale-48)/48.0);
    B = interpolate(255, 0, (greyscale-48)/48.0);
}
else if ...

Actually you could use the YUV color model since it is kind of based on two coordinates, ie U and V. 实际上,您可以使用YUV颜色模型,因为它基于两种坐标,即U和V。

This seems more appropriate for the task. 这似乎更适合该任务。

And YUV -> RGB conversion is pretty straightforward. YUV-> RGB转换非常简单。

You can convert RGB to HSL and increase the brightness/contrast. 您可以将RGB转换为HSL,并增加亮度/对比度。 You can find forumlas for the conversions and other useful info on this page: http://lodev.org/cgtutor/color.html 您可以在此页面上找到有关转换的论坛以及其他有用的信息: http ://lodev.org/cgtutor/color.html

I believe you want a heatmap based on the ordered values. 我相信您想要基于顺序值的热图。 Then you have different types of heatmaps. 然后,您将拥有不同类型的热图。 Solution here: http://www.andrewnoske.com/wiki/Code_-_heatmaps_and_color_gradients 此处的解决方案: http : //www.andrewnoske.com/wiki/Code_-_heatmaps_and_color_gradients

Use a different colour-space that means you can easily assign coordinates to different colours. 使用不同的颜色空间,这意味着您可以轻松地将坐标分配给不同的颜色。

YUV or YCrCb might suit as the UV or CrCb dimensions could be treated as "at right-angles" YUV或YCrCb可能适合,因为UV或CrCb尺寸可以视为“直角”

Or HSL/HSV if one of your dimensions wraps around like the hue does. 或HSL / HSV(如果您的其中一个尺寸像色相一样环绕)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM