3

我想知道是否有人有任何建议或可以向我指出有关创建用于图像合成的颜色查找表的任何好的资源。在我的应用程序中,我有介于 -1.0 和 1.0 之间的浮点值,需要映射到 RGB 空间。问题是,我事先不知道这些浮点值的精度是多少,所以我不知道要在查找表中放入多少条目或它们应该是什么。有没有常用的技术来处理这种形式的数据到颜色的映射?根据图像数据域中的值范围为每个图像创建一个新的颜色表似乎成本太高。

我想为映射定义一系列值会起作用,但请告诉我你的想法。此外,如果有人知道任何现有的工具(最好是基于 python 的)来创建颜色查找表,这将是有帮助的。

4

2 回答 2

1

如果您需要使用查找表并处理浮点数据,则必须将浮点数据量化为单独的范围,然后查找表中的每个范围。

但是,在这里使用查找表似乎不合适;为什么不定义一个将浮点值作为输入并返回 RGB 值的映射函数呢?我用它来为分形着色(参见http://jk.ozlabs.org/projects/lca2008-hackfest/中的“着色”部分)。

基本上,我的方法是做一个简化的 HSV 到 RSB 的转换,使用饱和度和值的常量值,以及色调的浮点输入数据。这将为您的值提供以下 RGB 输出:

i 到 RGB 转换

有关使用此映射函数着色的一些分形,请参阅http://jk.ozlabs.org/blog/post/65/hackfest08-solution-2/

我有一些 C 代码可以做到这一点,可以很容易地转换为 python。请注意,这假设 0 <= i <= 1,而您可能想要 -1 <= i <= 1:

/* for a value x (which is between x_min and x_max), interpolate a y value
 * (between y_min and y_max) of the same proportion.
 */
static float interpolate(float x, float x_min, float x_max,
        float y_min, float y_max)
{
    x = (x - x_min) / (x_max - x_min);
    return x * (y_max - y_min) + y_min;

}

/*
 * given a the i and i_max values from a point in our (x,y) coordinates,
 * compute the colour of the pixel at that point.
 *
 * This function does a simplified Hue,Saturation,Value transformation to
 * RGB. We take i/i_max as the Hue, and keep the saturation and value
 * components fixed.
 */
void colour_map(struct pixel *pix, float i, float i_max)
{
    const float saturation = 0.8;
    const float value = 0.8;
    float v_min, hue;

    hue = i / (i_max + 1);
    v_min = value * (1 - saturation);

    /* create two linear curves, between value and v_min, of the
     * proportion of a colour to include in the rgb output. One
     * is ascending over the 60 degrees, the other descending
     */

    if (hue < 0.25) {
        pix->r = value * 255;
        pix->g = interpolate(hue, 0.0, 0.25, v_min, value) * 255;
        pix->b = v_min * 255;

    } else if (hue < 0.5) {
        pix->r = interpolate(hue, 0.25, 0.5, value, v_min) * 255;
        pix->g = value * 255;
        pix->b = v_min * 255;

    } else if (hue < 0.75) {
        pix->r = v_min * 255;
        pix->g = value * 255;
        pix->b = interpolate(hue, 0.5, 0.75, v_min, value) * 255;

    } else {
        pix->r = v_min * 255;
        pix->g = interpolate(hue, 0.75, 1.0, value, v_min) * 255;
        pix->b = value * 255;
    }

    pix->a = 255;
}
于 2011-02-15T03:55:51.690 回答
1

您正在寻找的术语是假彩色图像

如何选择色带取决于您要显示的内容。简单的方法是将数据分成两半,在中间范围之上和之下

对于下半部分,您设置红色=0,然后蓝色=(255 - 您的价值),绿色=(您的价值)。这将为您提供介于最低值的最蓝色和最高值的绿色之间的颜色。

然后在高范围设置蓝色=0,红色=你的值,绿色=255-(你的值),这给你一个颜色,红色代表最高值,绿色代表最低值。

您还可以更改曲线的形状以强调特定范围

于 2011-02-09T00:06:31.597 回答