J= im2uint8(I)converts the grayscale, RGB, or binary imageItouint8, rescaling or offsetting the data as necessary.
If the input image is of classuint8, then the output image is identical. If the input image is of classlogical, thenim2uint8changes true-valued elements to 255.
J= im2uint8(I,'indexed')converts the indexed imageItouint8, offsetting the data if necessary.
Input image, specified as a numeric array or logical array of any size and dimension.
IfIis a grayscale or RGB image, then it can beuint8,uint16,double,logical,single, orint16. The intensity values for input image of classsingleordoublemust be in the range [0, 1].
Note
IfIis of classsingleordoublewith values outside the range [0, 1] then you can userescalefunction to rescale values to the expected range.
IfIis an indexed image, then it can beuint8,uint16,doubleorlogical.
Note
It is not always possible to convert an indexed image touint8. If the indexed image is of classdouble, then the maximum value must be 256 or less. If the indexed image is of classuint16, then the maximum value must be 255 or less.
IfIis a binary image, then it must belogical.
Data Types:single|double|int16|uint8|uint16|logical
Image with classuint8, returned as a numeric array of the same size as the input imageI.
Data Types:uint8
Extended Capabilities
C/C++ Code Generation Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
im2uint8supports the generation of C code (requiresMATLAB®Coder™). Note that if you choose the genericMATLAB Host Computertarget platform,im2uint8generates 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类型的代码创eration Support in Image Processing Toolbox.
GPU Code Generation Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Thread-Based Environment Run code in the background using MATLAB®backgroundPoolor accelerate code with Parallel Computing Toolbox™ThreadPool.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.