Compute statistics for labeled regions
Statistics
visionstatistics
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  Input/Output  Supported Data Types 

BW  Vector or matrix that represents a binary image  Boolean 
Area  Vector that represents the number of pixels in labeled regions  32bit signed integer 
Centroid  Mby2 matrix of centroid coordinates, where M represents the number of blobs 

BBox  Mby4 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.  32bit signed integer 
MajorAxis  Vector that represents the lengths of major axes of ellipses 

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 xaxis.  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 32bit unsigned integer 
Count  Scalar value that represents the actual number of labeled regions in each image  Same as Label port 
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.
vision
Select this check box to output a vector that represents the number of pixels in labeled regions
Select this check box to output an Mby2
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 x_{1}, y_{1} and x_{2}, y_{2},
respectively. The block outputs:
$$\left[\begin{array}{cc}{x}_{1}& {y}_{1}\\ {x}_{2}& {y}_{2}\end{array}\right]$$
at the Centroid port.
Select this check box to output an Mby4
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 upperleft 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.
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
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
Select this check box to output a vector that represents the
angles between the major axes of the ellipses and the xaxis.
The angle values are in radians and range between:
$$\frac{\pi}{2}$$ and $$\frac{\pi}{2}$$
Select this check box to output a vector that represents the eccentricities of ellipses that have the same second moments as the region
Select this check box to output a vector that represents the equivalent diameters squared
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
Select this check box to output an Nby1 vector of the perimeter lengths, in pixels, of each blob, where N is the number of blobs.
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
.
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}$$.
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.
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.
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.
Select this check box to output a scalar value that represents the actual number of connected regions in each image at the Count port.
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. The maximum
allowable value is the maximum of uint32
data type.
This parameter is tunable.
Select this check box to exclude a labeled blob that contains at least one border pixel.
Select this check box to output blob statistics as a variablesize signal. Selecting this check box means that you do not need to specify fill values.
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 variablesize signal check box.
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 variablesize 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
.
Select the rounding mode Floor
, Ceiling
, Nearest
or Zero
for
fixedpoint operations.
Select the overflow mode, Wrap
or Saturate
for
fixedpoint operations.
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.
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.
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.
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.
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.
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.
Select this parameter to prevent the autoscaling tool in the
FixedPoint Tool from overriding any fixedpoint scaling you specify
in this block mask. For more information, see fxptdlg
, a reference page on the FixedPoint
Tool in the Simulink documentation.
Computer Vision System Toolbox  
Image Processing Toolbox 