Convert image to 16-bit unsigned integers



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

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

You optionally can perform the conversion using a GPU (requires Parallel Computing Toolbox™).

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 or logical array of any size and dimension.

  • If I is a grayscale or RGB image, then it can be uint8, uint16, double, logical, single, or int16.

  • If I is an indexed image, then it can be uint8, uint16, double or logical.


    It is not always possible to convert an indexed image to uint8. If the indexed image is of class 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 class uint16, returned as a numeric array with the same size and dimensionality as I.

Data Types: uint16

Extended Capabilities

Introduced before R2006a