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

# Blob Analysis

Compute statistics for labeled regions

## Library

Statistics

`visionstatistics`

## Description

Use the Blob Analysis block to calculate statistics for labeled regions in a binary image. The block returns quantities such as the centroid, bounding box, label matrix, and blob count. The Blob Analysis block supports input and output variable size signals. You can also use the Selector block from Simulink®, to select certain blobs based on their statistics.

For information on pixel and spatial coordinate system definitions, see Image Coordinate Systems (Image Processing Toolbox) and Coordinate Systems.

### Port Descriptions

PortInput/OutputSupported Data Types

BW

Vector or matrix that represents a binary image

Boolean

Area

Vector that represents the number of pixels in labeled regions

32-bit signed integer

Centroid

M-by-2 matrix of centroid coordinates, where M represents the number of blobs

• Double-precision floating point

• Single-precision floating point

• Fixed point

BBox

M-by-4 matrix of [x y width height] bounding box coordinates, where M represents the number of blobs and [x y] represents the upper left corner of the bounding box.

32-bit signed integer

MajorAxis

Vector that represents the lengths of major axes of ellipses

• Double-precision floating point

• Single-precision floating point

MinorAxis

Vector that represents the lengths of minor axes of ellipses

Same as MajorAxis port

Orientation

Vector that represents the angles between the major axes of the ellipses and the x-axis.

Same as MajorAxis port

Eccentricity

Vector that represents the eccentricities of the ellipses

Same as MajorAxis port

Diameter ^2

Vector that represents the equivalent diameters squared

Same as Centroid port

Extent

Vector that represents the results of dividing the areas of the blobs by the area of their bounding boxes

Same as Centroid port

Perimeter

Vector containing an estimate of the perimeter length, in pixels, for each blob

Same as Centroid port

Label

Label matrix

8-, 16-, or 32-bit unsigned integer

Count

Scalar value that represents the actual number of labeled regions in each image

Same as Label port

## Dialog Box

The Main pane of the Blob Analysis dialog box appears as shown in the following figure. Use the check boxes to specify the statistics values you want the block to output. For a full description of each of these statistics, see the `regionprops` function reference page in the Image Processing Toolbox™ documentation.

Area

Select this check box to output a vector that represents the number of pixels in labeled regions

Centroid

Select this check box to output an M-by-2 matrix of [x y] centroid coordinates. The rows represent the coordinates of the centroid of each region, where M represents the number of blobs.

Example: Suppose there are two blobs, where the row and column coordinates of their centroids are x1, y1 and x2, y2, respectively. The block outputs:

`$\left[\begin{array}{cc}{x}_{1}& {y}_{1}\\ {x}_{2}& {y}_{2}\end{array}\right]$`
at the Centroid port.

Bounding box

Select this check box to output an M-by-4 matrix of [x y width height] bounding boxes. The rows represent the coordinates of each bounding box, where M represents the number of blobs.

Example: Suppose there are two blobs, where x and y define the location of the upper-left corner of the bounding box, and w, h define the width and height of the bounding box. The block outputs

`$\left[\begin{array}{cccc}{x}_{1}& {y}_{1}& {w}_{1}& {h}_{1}\\ {x}_{2}& {y}_{2}& {w}_{2}& {h}_{2}\end{array}\right]$`
at the BBox port.

Major axis length

Select this check box to output a vector with the following characteristics:

• Represents the lengths of the major axes of ellipses

• Has the same normalized second central moments as the labeled regions

Minor axis length

Select this check box to output a vector with the following characteristics:

• Represents the lengths of the minor axes of ellipses

• Has the same normalized second central moments as the labeled regions

Orientation

Select this check box to output a vector that represents the angles between the major axes of the ellipses and the x-axis. The angle values are in radians and range between:
$-\frac{\pi }{2}$ and $\frac{\pi }{2}$

Eccentricity

Select this check box to output a vector that represents the eccentricities of ellipses that have the same second moments as the region

Equivalent diameter squared

Select this check box to output a vector that represents the equivalent diameters squared

Extent

Select this check box to output a vector that represents the results of dividing the areas of the blobs by the area of their bounding boxes

Perimeter

Select this check box to output an N-by-1 vector of the perimeter lengths, in pixels, of each blob, where N is the number of blobs.

Statistics output data type

Specify the data type of the outputs as `double`, `single`, or to `Specify via Data Types tab`. The fields on the Data Types tab appear when you set the output data type to `Specify via Data Types tab`.

Connectivity

Define which pixels connect to each other. If you want to connect pixels located on the top, bottom, left, and right, select `4`. If you want to connect pixels to the other pixels on the top, bottom, left, right, and diagonally, select `8`. For more information about this parameter, see the Label block reference page.

The Connectivity parameter also affects how the block calculates the perimeter of a blob. For example:

The following figure illustrates how the block calculates the perimeter when you set the Connectivity parameter to `4`.

The block calculates the distance between the center of each pixel (marked by the black dots) and estimates the perimeter to be 22.

The next figure illustrates how the block calculates the perimeter of a blob when you set the Connectivity parameter to `8`.

The block takes a different path around the blob and estimates the perimeter to be $18+2\sqrt{2}$.

Output label matrix

Select this check box, to output the label matrix at the Label port. The pixels equal to `0` represent the background. The pixels equal to `1` represent the first object. The pixels equal to `2` represent the second object, and so on.

The Blob Properties pane of the Blob Analysis dialog box appears as shown in the following figure.

Maximum number of blobs

Specify the maximum number of labeled regions in each input image. The block uses this value to preallocate vectors and matrices to ensure that they are long enough to hold the statistical values. The maximum number of blobs the block outputs depends on both the value of this parameter, and on the size of the input image. The number of blobs the block outputs may be limited by the input image size.

Warn if maximum number of blobs is exceeded

Select this check box to output a warning when the number of blobs in an image is greater than the value of Maximum number of blobs parameter.

Output number of blobs found

Select this check box to output a scalar value that represents the actual number of connected regions in each image at the Count port.

Specify minimum blob area in pixels

Select this check box to enter the minimum blob area in the edit box that appears beside the check box. The blob gets a label if the number of pixels meets the minimum size specified. This parameter is tunable.

Specify maximum blob area in pixels

Select this check box to enter the maximum blob area in the edit box that appears beside the check box. The blob gets a label if the number of pixels meets the minimum size specified. The maximum allowable value is the maximum of `uint32` data type. This parameter is tunable.

Exclude blobs touching image border

Select this check box to exclude a labeled blob that contains at least one border pixel.

Output blob statistics as a variable-size signal

Select this check box to output blob statistics as a variable-size signal. Selecting this check box means that you do not need to specify fill values.

Fill empty spaces in outputs

Select this check box to fill empty spaces in the statistical vectors with the values you specify in the Fill values parameter.

The Fill empty spaces in outputs check box does not appear when you select the Output blob statistics as a variable-size signal check box.

Fill values

If you enter a scalar value, the block fills all the empty spaces in the statistical vectors with this value. If you enter a vector, it must have the same length as the number of selected statistics. The block uses each vector element to fill a different statistics vector. If the empty spaces do not affect your computation, you can deselect the Fill empty spaces in outputs check box. As a best practice, leave this check box selected.

The Fill values parameter is not visible when you select the Output blob statistics as a variable-size signal check box.

The Data Types pane of the Blob Analysis dialog box appears as shown in the following figure.

The parameters on the Data Types tab apply only when you set the Statistics output data type parameter to `Specify via Data Types tab`.

Rounding mode

Select the rounding mode `Floor`, `Ceiling`, `Nearest` or `Zero` for fixed-point operations.

Overflow mode

Select the overflow mode, `Wrap` or `Saturate` for fixed-point operations.

Product output

When you select `Binary point scaling`, you can enter the Word length and the Fraction length of the product output, in bits.

When you select `Slope and bias scaling`, you can enter the Word length in bits, and the Slope of the product output. All signals in the Computer Vision System Toolbox™ software have a bias of `0`.

The block places the output of the multiplier into the Product output data type and scaling. The computation of the equivalent diameter squared uses the product output data type. During this computation, the block multiplies the blob area (stored in the accumulator) by the 4/pi factor. This factor has a word length that equals the value of Equivalent diameter squared output data type Word length. The value of the Fraction length equals its word length minus two. Use this parameter to specify how to designate this product output word and fraction lengths.

Accumulator

When you select `Same as product output` the characteristics match the characteristics of the product output.

When you select `Binary point scaling`, you can enter the Word length and the Fraction length of the accumulator, in bits.

When you select `Slope and bias scaling`, you can enter the Word length, in bits, and the Slope of the Accumulator. All signals in the Computer Vision System Toolbox software have a bias of 0.

Inputs to the Accumulator get cast to the accumulator data type. Each element of the input gets added to the output of the adder, which remains in the accumulator data type. Use this parameter to specify how to designate this accumulator word and fraction lengths.

Centroid output

Choose how to specify the Word length and Fraction length of the output at the Centroid port:

• When you select `Same as accumulator`, these characteristics match the characteristics of the accumulator.

• When you select `Binary point scaling`, you can enter the Word length and Fraction length of the output, in bits.

• When you select `Slope and bias scaling`, you can enter the Word length, in bits, and the Slope of the output. All signals in the Computer Vision System Toolbox software have a bias of 0.

Equiv Diam^2 output

Choose how to specify the Word length and Fraction length of the output at the Diameter ^2 port:

• When you select `Same as accumulator`, these characteristics match the characteristics of the Accumulator.

• When you select `Same as product output`, these characteristics match the characteristics of the Product output.

• When you select `Binary point scaling`, you can enter the Word length and Fraction length of the output, in bits.

• When you select `Slope and bias scaling`, you can enter the Word length, in bits, and the Slope of the output. All signals in the Computer Vision System Toolbox software have a bias of 0.

Extent output

Choose how to specify the Word length and Fraction length of the output at the Extent port:

• When you select `Same as accumulator`, these characteristics match the characteristics of the accumulator.

• When you select `Binary point scaling`, you can enter the Word length and Fraction length of the output, in bits.

• When you select `Slope and bias scaling`, you can enter the Word length, in bits, and the Slope of the output. All signals in the Computer Vision System Toolbox software have a bias of 0.

Perimeter output

Choose how to specify the Word length and Fraction length of the output at the Perimeter port:

• When you select `Same as accumulator`, these characteristics match the characteristics of the accumulator.

• When you select `Binary point scaling`, you can enter the Word length and Fraction length of the output, in bits.

• When you select `Slope and bias scaling`, you can enter the word length, in bits, and the Slope of the output. All signals in the Computer Vision System Toolbox software have a bias of 0.

Lock data type settings against changes by the fixed–point tools

Select this parameter to prevent the autoscaling tool in the Fixed-Point Tool from overriding any fixed-point scaling you specify in this block mask. For more information, see `fxptdlg`, a reference page on the Fixed-Point Tool in the Simulink documentation.

 Label Computer Vision System Toolbox `regionprops` Image Processing Toolbox