[gpuarrayL,num]
= bwlabel(gpuarrayBW,n) performs
the labeling operation on a GPU. The input image and output image
are gpuArrays. The variable n can
be a numeric array or a gpuArray. This syntax requires
the Parallel Computing Toolbox™.

More About

When generating code, the parameter n must
be a compile-time constant.

The functions bwlabel, bwlabeln,
and bwconncomp all compute connected components
for binary images. bwconncomp replaces the use
of bwlabel and bwlabeln. It
uses significantly less memory and is sometimes faster than the other
functions.

Input
Dimension

Output Form

Memory Use

Connectivity

bwlabel

2-D

Double-precision label matrix

High

4 or 8

bwlabeln

N-D

Double-precision label matrix

High

Any

bwconncomp

N-D

CC struct

Low

Any

You can use the MATLAB find function
in conjunction with bwlabel to return vectors of
indices for the pixels that make up a specific object. For example,
to return the coordinates for the pixels in object 2, enter the following:.

[r, c] = find(bwlabel(BW)==2)

You can display the output matrix as a pseudocolor indexed image.
Each object appears in a different color, so the objects are easier
to distinguish than in the original image. For more information, see label2rgb.

To compute a label matrix having a more memory-efficient
data type (e.g., uint8 versus double),
use the labelmatrix function
on the output of bwconncomp.
For more information, see the reference page for each function.

To extract features from a binary image using regionprops with
default connectivity, just pass BW directly into regionprops,
i.e., regionprops(BW).

The bwlabel function
can take advantage of hardware optimization for data types logical, uint8,
and single to run faster. Hardware optimization
requires marker and mask to
be 2-D images and conn to be either 4 or 8.