Main Content

Differences Between Colormaps and Truecolor

Many graphics objects, such as surfaces, patches, and images, support two different techniques for specifying color: colormaps (which use indexed color) and truecolor. Each technique involves a different workflow and has a different impact on your visual presentation.

Differences in Workflow

A colormap is an m-by-3 array in which each row specifies an RGB triplet. To use a colormap in a graphical presentation, you assign an index to each location in your graphic. Each index addresses a row in the colormap to display a color at the specified location in the graphic. By contrast, using truecolor involves specifying an RGB triplet at every location in your graphic.

Here are some points to consider when deciding which to technique to use:

  • Truecolor is more direct. If you want to assign specific red, green, and blue values to specific locations in your graphic, it is usually easier to do it using truecolor.

  • Making changes in a region of the color palette is easier to do in a colormap. For example, if you want to brighten the transition from blue to green in a gradient, it is easier to edit those rows in the colormap than it is to edit the colors at the individual locations in your graphic.

  • 你的数据的格式可能更适合for one of the workflows. For example, many compressed GIF images are stored using indexed color.

Both coloring techniques use a color arrayCto specify the color information. The shape ofCdepends on the type of graphics object and the coloring method you choose. This table summarizes the differences.

Type of Graphics Object Property that Contains Color ArrayC Shape ofCfor Indexed Color Shape ofCfor Truecolor
Surface CData Cis an m-by-n array that is the same size as the z-coordinate array. The value atC(i,j)specifies the colormap index forZ(i,j). Cis an m-by-n-by-3 array, whereC(:,:,i)the same size as the z-coordinate array.

C(i,j,1)specifies the red component forZ(i,j).

C(i,j,2)specifies the green component forZ(i,j).

C(i,j,3)specifies the blue component forZ(i,j).
Image CData Cis an m-by-n array for an m-by-n image. The value atC(i,j)specifies the colormap index for pixel(i,j). Cis an m-by-n-by-3 array for an m-by-n image.

C(i,j,1)specifies the red component for pixel(i,j).

C(i,j,2)specifies the green component for pixel(i,j).

C(i,j,3)specifies the blue component for pixel(i,j).
Patch(x, y, z) CData To color patch faces,Cis a 1-by-m array for m patch faces.C(i)specifies the colormap index for facei.

To color patch vertices,Cis an m-by-n array, where m is the number of vertices per face, and n is the number of faces.C(i,j)specifies the colormap index for vertexiof facej.
To color patch faces,Cis an m-by-3 array for m patch faces.C(i,:)specifies the red, green, and blue values for facei.

To color patch vertices,Cis an n-by-3 array, where n is the total number of vertices.C(i,:)specifies the red, green, and blue values for vertexi.
Patch(face-vertex data) FaceVertexCData To color patch faces,Cis a 1-by-m array for m patch faces.C(i)specifies the colormap index for facei.

To color patch vertices,Cis a 1-by-n array, where n is the total number of vertices.C(i)specifies the colormap index for vertexi.
To color patch faces,Cis an m-by-3 array for m patch faces.C(i,:)specifies the red, green, and blue values for facei.

To color patch vertices,Cis an n-by-3 array, where n is the total number of vertices.C(i,:)specifies the red, green, and blue values for vertexi.

不同的可视化表示

Colormaps offer a palette of m colors, where m is the length of the colormap. By contrast, truecolor offers a palette of 256 × 256 × 256 ≈ 1.68 million colors.

Consider these factors as you decide how large your color palette needs to be:

  • Smaller color palettes are the most economical way to fill large regions with solid color. They are also useful in visualizing contours of surfaces.

  • Larger color palettes are better for showing subtle transitions and smooth color gradients.

Interpolating vertex colors across a patch face is one situation in which the differences between indexed color and truecolor are more noticeable. The following two patches illustrate an extreme case. The patch on the left uses a small colormap, whereas the patch on the right uses truecolor.

If you are concerned about the limited palette of a colormap, you can add more colors to it.Change Color Scheme Using a Colormapshows how to use a colormap with a specific number of colors.

Related Topics