im2uint8
Convert image to 8-bit unsigned integers
Description
Examples
Convert uint16 Array to uint8 Array
Create an array of data type 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 data type 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
Input Arguments
I
— Input image
numeric array | logical array
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 beuint8
,uint16
,double
,logical
,single
, orint16
. The intensity values for input image of classsingle
ordouble
must be in the range [0, 1].Note
If
I
is of classsingle
ordouble
with values outside the range [0, 1] then you can userescale
function to rescale values to the expected range.If
I
is an indexed image, then it can beuint8
,uint16
,double
orlogical
.Note
It is not always possible to convert an indexed image to
uint8
. 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.If
I
is a binary image, then it must belogical
.
Data Types: single
| double
| int16
| uint8
| uint16
| logical
Output Arguments
J
— Image with class uint8
numeric array
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 genericMATLAB 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 Types of Code Generation 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® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Image Processing on a GPU.
Version History
Introduced before R2006aR2021b: Support for thread-based environments
im2uint8
now supports thread-based
environments.
Beispiel öffnen
Sie haben eine geänderte Version dieses Beispiels. Möchten Sie dieses Beispiel mit Ihren Änderungen öffnen?
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
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.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)