Main Content


Convert image to 16-bit unsigned integers



J = im2uint16(I) converts the grayscale, RGB, or binary image I to data type uint16, rescaling or offsetting the data as necessary.

If the input image is of data type uint16, then the output image is identical. If the input image is of data type logical, then im2uint16 changes true-valued elements to 65535.

J = im2uint16(I,"indexed") converts the indexed image I to uint16, offsetting the data if necessary.


collapse all

Create an array of class double.

I = reshape(linspace(0,1,20),[5 4])
I = 5×4

         0    0.2632    0.5263    0.7895
    0.0526    0.3158    0.5789    0.8421
    0.1053    0.3684    0.6316    0.8947
    0.1579    0.4211    0.6842    0.9474
    0.2105    0.4737    0.7368    1.0000

Convert the array to class uint16.

I2 = im2uint16(I)
I2 = 5x4 uint16 matrix

       0   17246   34492   51738
    3449   20695   37941   55187
    6898   24144   41391   58637
   10348   27594   44840   62086
   13797   31043   48289   65535

Input Arguments

collapse all

Input image, specified as a numeric array or logical array of any size and dimension.

  • If I is a grayscale or RGB image, then it can be of data type uint8, uint16, int16, double, single, or logical. The im2uint16 function expects images of data type double and single to have values in the range [0, 1]. If I has values outside the range [0, 1], then you can rescale values to the expected range by using the rescale function.

  • If I is an indexed image, then it can be of data type uint8, uint16, double, or logical. If the indexed image is of data type double, then the maximum value must be 65536 or less.

  • If I is a binary image, then it must be logical.

Data Types: single | double | int16 | uint8 | uint16 | logical

Output Arguments

collapse all

Image with data type uint16, returned as a numeric array of the same size as the input image I.

Data Types: uint16

Extended Capabilities

Version History

Introduced before R2006a

expand all