label2idx
Convert label matrix to cell array of linear indices
Description
converts the regions described by the label matrix pixelIndexList
= label2idx(L
)L
into
linear indices pixelIndexList
.
Examples
Calculate Pixel Index List for Small Label Matrix
Create a small sample matrix containing three regions.
BW = logical([1 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 0 0 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 1 1 0 1 1 1 0 0 0 0 0]);
Create a label matrix from this sample image.
L = bwlabel(BW)
L = 8×8
1 1 1 0 0 0 0 0
1 1 1 0 2 2 0 0
1 1 1 0 2 2 0 0
1 1 1 0 0 0 0 0
1 1 1 0 0 0 3 0
1 1 1 0 0 0 3 0
1 1 1 0 0 3 3 0
1 1 1 0 0 0 0 0
Get a linear index list of all the pixels in each region. The function returns a cell array with an element for each region it finds in the label matrix.
pixelIndexList = label2idx(L)
pixelIndexList=1×3 cell array
{24x1 double} {4x1 double} {4x1 double}
Examine one of the pixel index lists returned. For example, look at the second cell in the returned cell array. It contains the linear indices for all the pixels in the region labeled "2". The upper left corner of the region is pixel BW(2,5), which is the 34th pixel in linear indexing.
pixelIndexList{2}
ans = 4×1
34
35
42
43
Input Arguments
L
— Label matrix
numeric array
Label matrix, specified as a numeric array of any dimension.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
Output Arguments
pixelIndexList
— Linear indices of pixels in regions
1-by-n cell array
Linear indices of pixels in regions, returned as a 1-by-n cell array. Each
element of the output, pixelIndexList{n}
, is a vector
that contains all the linear indices in L
where
L
is equal to n
.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
label2idx
supports the generation of C
code (requires MATLAB®
Coder™). For more information, see Code Generation for Image Processing.
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.
Version History
Introduced in R2016aR2022b: Support for thread-based environments
label2idx
now supports thread-based
environments.
See Also
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
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)