开发者

Value as colour representation

开发者 https://www.devze.com 2023-03-30 18:46 出处:网络
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)

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)

  1. Value as shades of grey
  2. Value as brightness of a base colour (e.g. brightness of blue)

But what is the best algorithm when I want to use the full colour range ("all colours"). When I use "greys" with 8bit RGB values, I actually do have a representation of 256 shades (white to black). But if I use the whole range, I could use more shades. Something like this. Also this would be easier to recognize.

Basically I need the algorithm in Javascript, but I guess all code such as C#, Java, pseudo code would do as well. The legend at the bottom shows the encoding, and I am looking for the algorithm for this.

So having a range of values(e.g. 1-1000), I could represent 1 as white and 1000 as black, but I could also represent 1 as yellow and 1000 as blue. But is there a standard algorithm for this? Looking at the example here, it is shown that they use colour intervals. I do not only want to use greys or change the brightness, but use all colours.

This is a visual demonstration (Flash required). Given values a represented in a color scheme, my goal is to calc开发者_运维技巧ulate the colours.

I do have a linear colour range, e.g. from 1-30000

-- Update --

Here I found that here is something called a LabSpace:

Lab space is a way of representing colours where points that are close to each other are those that look similar to each other to humans.

So what I would need is an algorithm to represent the linear values in this lab space.


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.


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.


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.")


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

精彩评论

暂无评论...
验证码 换一张
取 消