Function File: im2uint8 (img)
Function File: im2uint8 (img, "indexed")

Convert image to uint8.

The conversion of img to an 8-bit unsigned integer, is dependent on the type of input image. The following input classes are supported for non-indexed images:

int16 or uint16

Values are rescaled to the range of the uint8 class [0 255].

logical

True and false values are assigned a value of 0 and 255 respectively.

double or single

Values are truncated to the interval [0 1] and then rescaled to the range of values of the uint8 class [0 255].

uint8

Returns the same image.

If the second argument is the string "indexed", then values are cast to uint8, and a -1 offset is applied if input is a floating point class. Input checking is performed and an error will be throw is the range of values in uint8 is not enough for all the image indices.

See also: im2bw, imcast, im2double, im2int16, im2single, im2uint16.

Package: image