Value as colour representation

后端 未结 4 579
误落风尘
误落风尘 2021-01-27 14:32

Converting a value to a colour is well known, I do understand the following two approaches (very well described in changing rgb color values to represent a value)

相关标签:
4条回答
  • 2021-01-27 15:01

    Horst,

    The example you gave does not create gradients. Instead, they use N preset colors from an array and pick the next color as umbr points out. Something like this:

    a = { "#ffffff", "#ff00ff", "#ff0000", "#888888", ... };
    c = a[pos / 1000];
    

    were pos is your value from 1 to 30,000 and c is the color you want to use. (you'd need to better define the index than pos / 1000 for this to work right in all situations.)

    If you want a gradient effect, you can just use the simple math shown on the other answer you pointed out, although if you want to do that with any number of points, it has to be done with triangles. You'll have a lot of work to determine the triangles and properly define every point.

    In JavaScript, it will be dog slow. (with OpenGL it would be instantaneous and you would not even have to compute the gradients, and that would be "faster than realtime.")

    0 讨论(0)
  • 2021-01-27 15:14

    What you need is a transfer function.
    given a float number, a transfer function can generate a color.

    see this:

    http://http.developer.nvidia.com/GPUGems/gpugems_ch39.html

    and this:

    http://graphicsrunner.blogspot.com/2009/01/volume-rendering-102-transfer-functions.html

    the second article says that the isovalue is between [0,255]. But it doesn't have to be in that range.

    Normally, we scale any float number to the [0,1] range, and apply transfer function to get the color value.

    0 讨论(0)
  • 2021-01-27 15:15

    There are two basic ways to specify colors. One is a pre-defined list of colors (a palette) and then your color value is an index into this list. This is how old 8-bit color systems worked, and how GIF images still work. There are lists of web-safe colors, eg http://en.wikipedia.org/wiki/Web_colors, that typically fit into an 8-bit value. Often similar colors are adjacent, but sometimes not. A palette has the advantage of requiring a small amount of data per pixel, but the disadvantage that you're limited in the number of different colors that can be on the screen at the same time.

    The other basic way is to specify the coordinates of a color. One way is RGB, with a separate value for each primary color. Another is Hue/Saturation/Luminance. CMYK (Cyan, Magenta, Yellow and sometimes blacK) is used for print. This is what's typically referred to as true color and when you use a phrase like "all colors" it sounds like you're looking for a solution like this. For gradients and such HSL might be a perfect fit for you. For example, a gradient from a color to grey simply reduces the saturation value. If all you want are "pure" colors, then fix the saturation and luminance values and vary the hue. Nearly all drawing systems require RGB, but the conversion from HSL to RGB is straight forward. http://en.wikipedia.org/wiki/HSL_and_HSV

    If you can't spare the full 24 bits per color (8 bits per color, 32-bit color is the same but adds a transparency channel) you can use 15 or 16 bit color. It's the same thing, but instead of 8 bits per color you get 5 each (15 bit) or 5-6-5 (16 bit, green gets the extra bit because our eyes are more sensitive to shades of green). That fits into a short integer.

    0 讨论(0)
  • 2021-01-27 15:19

    It depends on the purposes of your datasets.
    For example, you can assign a color to each range of values (0-100 - red, 100-200 - green, 200-300 - blue) by changing the brightness within the range.

    0 讨论(0)
提交回复
热议问题