Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
pmi432 / LR07 / 2read / image processing toolbox guide.pdf
Скачиваний:
150
Добавлен:
18.03.2015
Размер:
18.08 Mб
Скачать

Labeling and Measuring Objects in a Binary Image

Labeling and Measuring Objects in a Binary Image

In this section...

“Understanding Connected-Component Labeling” on page 10-39 “Selecting Objects in a Binary Image” on page 10-41

“Finding the Area of the Foreground of a Binary Image” on page 10-42 “Finding the Euler Number of a Binary Image” on page 10-43

Understanding Connected-Component Labeling

A connected component in a binary image is a set of pixels that form a connected group. For example, the binary image below has three connected components.

Connected component labeling is the process of identifying the connected components in an image and assigning each one a unique label, like this:

10-39

10 Morphological Operations

The matrix above is called a label matrix.

bwconncomp computes connected components, as shown in the example:

cc = bwconncomp(BW) cc =

Connectivity: 8 ImageSize: [8 9]

NumObjects: 3

PixelIdxList: {[6x1 double] [6x1 double] [5x1 double]}

The PixelIdxList identifies the list of pixels belonging to each connected component.

For visualizing connected components, it is useful to construct a label matrix. Use the labelmatrix function. To inspect the results, display the label matrix as a pseudo-color image using label2rgb.

Construct a label matrix:

labeled = labelmatrix(cc);

Create a pseudo-color image, where the label identifying each object in the label matrix maps to a different color in the associated colormap matrix. Use label2rgb to choose the colormap, the background color, and how objects in the label matrix map to colors in the colormap:

10-40

Соседние файлы в папке 2read