This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Image Type Conversion

Convert between the image types, such as RGB (truecolor), binary, grayscale, and indexed.

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

gray2indConvert grayscale or binary image to indexed image
ind2grayConvert indexed image to grayscale image
mat2grayConvert matrix to grayscale image
rgb2grayConvert RGB image or colormap to grayscale
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
multithresh Multilevel 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
im2java2dConvert image to Java buffered image
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 binary, indexed, grayscale, and truecolor image types.

Binary Images

In a binary image, each pixel assumes one of only two discrete values: 1 or 0.

Indexed Images

An indexed image consists of an array and a colormap matrix.

Grayscale Images

A grayscale image (also called gray-scale, gray scale, or gray-level) is a data matrix whose values represent intensities within some range.

Truecolor Images

A truecolor image is an image in which each pixel is specified by three values — one each for the red, blue, and green components of the pixel's color.

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 Classes

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

Display Separated Color Channels of an RGB Image

This example creates a simple truecolor image and then separates the color channels (planes).