Main Content

cmap2gray

Convert RGB colormap to grayscale colormap

    Description

    example

    newmap= cmap2gray(map)converts the RGB colormapmapinto the equivalent grayscale colormapnewmap.

    Examples

    collapse all

    Load an indexed image with its colormap into the workspace. Theloadcommand returns a structure containing the image data and the colormap. View the image.

    indImage = load('clown.mat'); figure imshow(indImage.X,indImage.map)

    Figure contains an axes object. The axes object contains an object of type image.

    Convert the RGB colormap that came with the image into a grayscale colormap.

    newmap = cmap2gray(indImage.map);

    Display the image with the grayscale colormap.

    figure; imshow(indImage.X,newmap)

    Figure contains an axes object. The axes object contains an object of type image.

    Input Arguments

    collapse all

    RGB colormap, specified as ac-by-3 numeric matrix with values in the range [0, 1]. Each row ofmapis a three-element RGB triplet that specifies the red, green, and blue components of a single color of the colormap.

    如果你有Computin平行g Toolbox™ installed,mapcan also be agpuArray.

    Data Types:double

    Output Arguments

    collapse all

    Grayscale colormap, returned as ac-by-3 numeric matrix with values in the range [0, 1]. The three columns ofnewmapare identical, so that each row specifies a single intensity value.

    如果你有Computin平行g Toolbox installed, thennewmapcan also be a gpuArray.

    Data Types:double

    Extended Capabilities

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    Version History

    Introduced in R2020b

    See Also

    |||(Image Processing Toolbox)

    Topics