im2uint8 - Convert image to 8-bit unsigned integers

Syntax

I2 = im2uint8(I1)
RGB2 = im2uint8(RGB1)
I = im2uint8(BW)
X2 = im2uint8(X1,'indexed')

Description

im2uint8 takes an image as input and returns an image of class uint8. If the input image is of class uint8, the output image is identical to the input image. If the input image is not uint8, im2uint8 returns the equivalent image of class uint8, rescaling or offsetting the data as necessary.

I2 = im2uint8(I1) converts the grayscale image I1 to uint8, rescaling the data if necessary.

RGB2 = im2uint8(RGB1) converts the truecolor image RGB1 to uint8, rescaling the data if necessary.

I = im2uint8(BW) converts the binary image BW to a uint8 grayscale image, changing 1-valued elements to 255.

X2 = im2uint8(X1,'indexed') converts the indexed image X1 to uint8, offsetting the data if necessary. Note that it is not always possible to convert an indexed image to uint8. If X1 is of class double, the maximum value of X1 must be 256 or less; if X1 is of class uint16, the maximum value of X1 must be 255 or less.

Class Support

Grayscale and truecolor images can be uint8, uint16, int16, single, double, or logical. Indexed images can be uint8, uint16, double, or logical. Binary input images must be logical. The output image is uint8.

Examples

I1 = reshape(uint16(linspace(0,65535,25)),[5 5])
I2 = im2uint8(I1)

See Also

im2double, im2int16, im2single, im2uint16, uint8

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS