Main Content

ind2rgb8

Convert indexed image to RGB image of type uint8

    Description

    RGB = ind2rgb8(X,cmap) converts the indexed image X and corresponding colormap cmap to an RGB (truecolor) image of type uint8.

    example

    Examples

    collapse all

    Read imagery of Concord, MA into the workspace.

    [X,cmap] = imread("concord_ortho_e.tif");
    whos X cmap
      Name         Size                Bytes  Class     Attributes
    
      X         2000x2000            4000000  uint8               
      cmap       256x3                  6144  double              
    

    The indexed image X is a 2000-by-2000 matrix of type uint8, and the colormap cmap is a 256-by-3 matrix of type double. The dimensions of cmap indicate that the indexed image contains up to 256 colors.

    Convert the indexed image to an RGB image. The result is a 2000-by-2000-by-3 array of type uint8.

    RGB = ind2rgb8(X,cmap);

    Check that the values of the RGB image are in the range [0, 255].

    [minVal,maxVal] = bounds(RGB(:))
    minVal = uint8
    
    0
    
    maxVal = uint8
    
    203
    

    Input Arguments

    collapse all

    Indexed image, specified as an m-by-n matrix of integers.

    • If you specify X as an array of an integer data type, then the value 0 corresponds to the first color in the colormap cmap. For a colormap containing c colors, values of the image X are clipped to the range [0, c–1].

    • If you specify X as an array of data type single or double, then the value 1 corresponds to the first color in the colormap. For a colormap containing c colors, values of the image X are clipped to the range [1, c].

    Data Types: double | uint8 | uint16 | uint32

    Colormap associated with the indexed image X, specified as a c-by-3 matrix with values in the range [0, 1]. Each row of cmap is a three-element RGB triplet that specifies the red, green, and blue components of a single color of the colormap.

    Data Types: double

    Output Arguments

    collapse all

    RGB image, returned as an m-by-n-by-3 numeric array with values in the range [0, 255].

    Data Types: uint8

    Version History

    Introduced before R2006a