You are here : matlabImage Processingim2uint8

im2uint8() - Image Processing

I2 = im2uint8(I) converts
the grayscale image I to uint8.
 If the input image is of class uint8, the output
image is identical to the input image.  If the input image is not uint8, im2uint8 returns
the equivalent image of class uint8, rescaling
or offsetting the data as necessary.RGB2 = im2uint8(RGB) converts
the truecolor image RGB to uint8,
rescaling the data if necessary.I = im2uint8(BW) converts
the binary image BW to a uint8 grayscale
image, changing 1-valued elements to 255.X2 = im2uint8(X,'indexed') converts
the indexed image X to uint8,
offsetting the data if necessary. Note that it is not always possible
to convert an indexed image to uint8. If X is
of class double, the maximum value of X must
be 256 or less. If X is of class uint16,
the maximum value of X must be 255 or less.examplegpuarrayB = im2uint8(gpuarrayA,___) performs
the conversion on a GPU. The input image, gpuarrayA,
can be a grayscale, truecolor, binary, or indexed gpuArray image.
The output image is a gpuArray. This syntax requires the Parallel Computing Toolbox™.Code Generation support:
Yes.MATLAB Function Block support:
Yes.


Syntax

I2 = im2uint8(I) exampleRGB2 = im2uint8(RGB)I = im2uint8(BW)X2 = im2uint8(X,'indexed')gpuarrayB = im2uint8(gpuarrayA,___) example


Example

Convert uint16 Array to uint8 ArrayOpen This Example
Create an array of class uint16.I = reshape(uint16(linspace(0,65535,25)),[5 5])

I =

      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 =

    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

Convert uint16 Array to uint8 on a GPUCreate array of class uint16.I1 = gpuArray(reshape(uint16(linspace(0,65535,25)),[5 5]))
Convert array to uint8.I2 = im2uint8(I1);


Output / Return Value


Limitations


Alternatives / See Also


Reference