Question: I have an array of pixels with an associated intensity (as a float between 0 and 1) that I would like to convert to a RGB image.

The easiest way would be to just multiply each value by 255 and assign it to R+G+B to obtain a greyscale image, but I think it would be better to use a whole range of colors to show finer differences.

As far as I know this is called a pseudo/false color image, but I am having a hard time finding algorithms for it. Right now I am using this code, but I was wondering if there was a smarter/faster way to do it:

```
 if(intensity <= 0.25) {
  p->r = 0;
  p->g = 0;
  p->b = (intensity) * 4 * 255;
  return;
 }

 if(intensity <= 0.5) {
  p->r = 0;
  p->g = (intensity - 0.25) * 4 * 255;
  p->b = 255;
  return;
 }

 if(intensity <= 0.75) {
  p->r = 0;
  p->g = 255;
  p->b = (0.75 - intensity) * 4 * 255;
  return;
 }

 if(intensity <= 1.0) {
  p->r = (intensity - 0.75) * 4 * 255;
  p->g = (1.0 - intensity) * 4 * 255;
  p->b = 0;
  return;
 }

```

Also, are there any standard color palettes I should use for this?

Answer: 
You could use **HSV or HSL** instead.

Try using your 0 to 1 value to set the Hue and use constants for saturation and value. You'll find plenty of example code for converting your HSV value to an RGB value.

<http://en.wikipedia.org/wiki/HSL_and_HSV>

When you see an "artificial colours" image, this is often what is used. The benefit is that all areas of the image are bright, with "dark" parts of the image simply coming out a different colour. 

If you use HSL you can also set the Lightness to 50% for most of your 0-1 range, but allowing it to go up right near the end (eg from 0.9 to 1), which will help bring the very intense parts of your image up to white.

Another option is to use a **False Colour Palette**. Here, you simply create an 8-bit image, and create a palette for it that suits your needs. There are some good examples of these [here...](http://en.wikipedia.org/wiki/List_of_software_palettes#False_color_palettes)
Define a bunch of RGB values and the intensity they will correspond to. Each of the intensities in your image will lie between two of these points - you can multiply by a constant and truncate, then look them up in an array. Once you have the two RGB values, interpolate between them based on the distance between the image intensity and the intensities of the two endpoints.