Main Content

Image Type Conversion

Convert between the image types, such as RGB (truecolor), binary, grayscale, and indexed images, and change the data type of an image

Image Processing Toolbox™ supports binary, indexed, grayscale, and truecolor image types. In each image type, pixels are stored in different formats. For example, truecolor images represent a pixel as a triplet of red, green, and blue values, whereas grayscale images represent a pixel as a single intensity value.

Pixel values of the different image types can be stored in floating-point, signed and unsigned integers, or logical data types. Toolbox functions enable you to convert between the image types and data types.

Functions

expand all

cmap2grayConvert RGB colormap to grayscale colormap (Since R2020b)
gray2indConvert grayscale or binary image to indexed image
im2grayConvert RGB image to grayscale (Since R2020b)
ind2grayConvert indexed image to grayscale image
mat2grayConvert matrix to grayscale image
rgb2grayConvert RGB image or colormap to grayscale
rgb2lightnessConvert RGB color values to lightness values
rgb2indConvert RGB image to indexed image
ind2rgbConvert indexed image to RGB image
label2rgbConvert label matrix into RGB image
demosaicConvert Bayer pattern encoded image to truecolor image
imsplitSplit multichannel image into its individual channels
imbinarizeBinarize 2-D grayscale image or 3-D volume by thresholding
adaptthreshAdaptive image threshold using local first-order statistics
otsuthreshGlobal histogram threshold using Otsu's method
graythreshGlobal image threshold using Otsu's method
imquantizeQuantize image using specified quantization levels and output values
multithreshMultilevel image thresholds using Otsu’s method
graysliceConvert grayscale image to indexed image using multilevel thresholding
im2doubleConvert image to double precision
im2int16Convert image to 16-bit signed integers
im2singleConvert image to single precision
im2uint16Convert image to 16-bit unsigned integers
im2uint8Convert image to 8-bit unsigned integers

Topics

  • Image Types in the Toolbox

    Image types determine how MATLAB® interprets data matrix elements as pixel intensity values. The toolbox supports many image types including binary, grayscale, truecolor, multispectral, and label images.

  • Convert Between Image Types

    Certain image processing operations support only a subset of the image types. You can convert images between the image types to suit the operation.

  • Convert Image Data Between Data Types

    You can convert image data between data types using functions that automatically rescale and offset the original data.

Featured Examples