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.
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 uint8, uint16,
double, logical,
single, or int16. The
intensity values for input image of class
single or double must
be in the range [0, 1].
Note
If I is of class
single or double
with values outside the range [0, 1] then you can use
rescale function to rescale values to the
expected range.
If I is an indexed image, then 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, then it must be
logical.
Data Types: single | double | int16 | uint8 | uint16 | logical
Image with class uint8, returned as a numeric array of
the same size as the input image I.
Data Types: uint8
Extended Capabilities
C/C++ Code Generation Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
im2uint8 supports the generation of C
code (requires MATLAB®
Coder™). Note that if you choose the generic MATLAB Host Computer
target platform, im2uint8 generates code that uses a precompiled,
platform-specific shared library. Use of a shared library preserves performance optimizations
but limits the target platforms for which code can be generated. For more information, see Code Generation Using a Shared Library.
GPU Code Generation Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
GPU Arrays Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.