# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# label2idx

Convert label matrix to cell array of linear indices

## Syntax

``pixelIndexList = label2idx(L)``

## Description

example

````pixelIndexList = label2idx(L)` converts the regions described by the label matrix `L` into the 1-by-N cell array of linear indices `pixelIndexList`. ```

## Examples

collapse all

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 = 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 = 1x3 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 = 34 35 42 43 ```

## Input Arguments

collapse all

Label matrix, specified as a real, nonsparse, nonnegative, finite numeric N-D matrix.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `uint8` | `uint16` | `uint32`

## Output Arguments

collapse all

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`.