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

Labeling and Measuring Objects in a Binary Image

RGB_label = label2rgb(labeled, @copper, 'c', 'shuffle'); imshow(RGB_label,'InitialMagnification','fit')

Remarks

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 older functions.

 

Function

Input

Output Form

Memory Use

Connectivity

 

 

 

Dimension

 

 

 

 

 

bwlabel

2-D

Double-precision label

High

4 or 8

 

 

 

 

matrix

 

 

 

 

bwlabeln

N-D

Double-precision label

High

Any

 

 

 

 

matrix

 

 

 

 

bwconncomp

N-D

CC struct

Low

Any

 

 

 

 

 

 

 

 

Selecting Objects in a Binary Image

You can use the bwselect function to select individual objects in a binary image. You specify pixels in the input image, and bwselect returns a binary image that includes only those objects from the input image that contain one of the specified pixels.

10-41

10 Morphological Operations

You can specify the pixels either noninteractively or with a mouse. For example, suppose you want to select objects in the image displayed in the current axes. You type

BW2 = bwselect;

The cursor changes to crosshairs when it is over the image. Click the objects you want to select; bwselect displays a small star over each pixel you click. When you are done, press Return. bwselect returns a binary image consisting of the objects you selected, and removes the stars.

See the reference page for bwselect for more information.

Finding the Area of the Foreground of a Binary Image

The bwarea function returns the area of a binary image. The area is a measure of the size of the foreground of the image. Roughly speaking, the area is the number of on pixels in the image.

bwarea does not simply count the number of pixels set to on, however. Rather, bwarea weights different pixel patterns unequally when computing the area. This weighting compensates for the distortion that is inherent in representing a continuous image with discrete pixels. For example, a diagonal line of 50 pixels is longer than a horizontal line of 50 pixels. As a result of the weighting bwarea uses, the horizontal line has area of 50, but the diagonal line has area of 62.5.

This example uses bwarea to determine the percentage area increase in circbw.tif that results from a dilation operation.

BW = imread('circbw.tif'); SE = ones(5);

BW2 = imdilate(BW,SE);

increase = (bwarea(BW2) - bwarea(BW))/bwarea(BW) increase =

0.3456

10-42

Labeling and Measuring Objects in a Binary Image

See the reference page for bwarea for more information about the weighting pattern.

Finding the Euler Number of a Binary Image

The bweuler function returns the Euler number for a binary image. The Euler number is a measure of the topology of an image. It is defined as the total number of objects in the image minus the number of holes in those objects. You can use either 4- or 8-connected neighborhoods.

This example computes the Euler number for the circuit image, using 8-connected neighborhoods.

BW1 = imread('circbw.tif'); eul = bweuler(BW1,8)

eul =

-85

In this example, the Euler number is negative, indicating that the number of holes is greater than the number of objects.

10-43

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