Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

im2uint8

Convert image to 8-bit unsigned integers

Syntax

J = im2uint8(I)
J = im2uint8(I,'indexed')
gpuarrayJ = im2uint8(gpuarrayI)
gpuarrayJ = im2uint8(gpuarrayI,'indexed')

Description

example

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

If the input image is of class uint8, then the output image is identical. If the input image is of class logical, then im2uint8 changes true-valued elements to 255.

J = im2uint8(I,'indexed') converts the indexed image I to uint8, offsetting the data if necessary.

example

gpuarrayJ = im2uint8(gpuarrayI) and

gpuarrayJ = im2uint8(gpuarrayI,'indexed') perform the conversion on a GPU. This syntax requires the Parallel Computing Toolbox™.

Examples

collapse all

Create an array of class uint16.

I = reshape(uint16(linspace(0,65535,25)),[5 5])
I = 5x5 uint16 matrix

       0   13653   27306   40959   54613
    2731   16384   30037   43690   57343
    5461   19114   32768   46421   60074
    8192   21845   35498   49151   62804
   10923   24576   38229   51882   65535

Convert the array to class uint8 .

I2 = im2uint8(I)
I2 = 5x5 uint8 matrix

     0    53   106   159   213
    11    64   117   170   223
    21    74   128   181   234
    32    85   138   191   244
    43    96   149   202   255

Create array of class uint16.

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

Convert array to uint8.

I2 = im2uint8(I1);

Input Arguments

collapse all

Input image, specified as a numeric matrix of any size and dimension.

  • If I is an intensity or RGB image, it can be uint8, uint16, double, logical, single, or int16.

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

    Note

    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 256 or less. If the indexed image is of class uint16, then the maximum value must be 255 or less.

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

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

Image when run on a GPU, specified as gpuArray containing an image described by I.

Output Arguments

collapse all

Image with class uint8, returned as a numeric matrix with the same size and dimensionality as I.

Data Types: uint8

Image with class uint8 when run on a GPU, returned as gpuArray containing an image described by J.

Extended Capabilities

Introduced before R2006a

Was this topic helpful?