FUNCTION REFERENCE

im2uint8

Convert an image to 8-bit unsigned integers.

Convert an image to 8-bit unsigned integers.

Syntax

I2 = im2uint8(I)

Syntax

I2 = im2uint8(X, 'indexed')

Double and single data are clipped to [0, 1], multiplied by 255 and rounded half away from zero (NaN gives 0); uint16 is divided by 257 and int16 offset by 32768 then divided by 257 (rounded); logical true gives 255. With 'indexed', floating indices (1-based) get 1 subtracted and must fit in 0..255.

Example

im2uint8([-1 0 0.5 1 2])   % uint8 [0 0 128 255 255]

Example

im2uint8(uint16([0 257 65535]))   % uint8 [0 1 255]

Differences from MATLAB: none known for double, single, logical, uint8, uint16 and int16 input.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.