Statistics for labeled regions
Computer Vision Toolbox / Statistics
The Blob Analysis block calculates 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 variablesize 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.
BW
— Binary imageBinary image, specified as a vector or matrix
Data Types: Boolean
Area
— Number of pixels in labeled regionsNumber of pixels in labeled regions, returned as a vector.
To enable this port, select the Area parameter.
Data Types: int32
Centroid
— Centroid coordinatesMby2 matrix of M number of blobs.
The rows represent the coordinates of the centroid of each region, and M represents the number of blobs.
For example, there are two blobs where the row and column coordinates of their centroids are x_{1}, y_{1} and x_{2}, y_{2}. The block outputs:
$$\left[\begin{array}{cc}{x}_{1}& {y}_{1}\\ {x}_{2}& {y}_{2}\end{array}\right]$$
at the Centroid port.
To enable this port, select the Centroid parameter.
Data Types: double
 single
 fixed point
BBox
— Bounding box coordinatesBounding box coordinates, returned as an Mby4 matrix of M bounding boxes for blobs. Each row of the matrix defines a bounding box as a fourelement vector [x,y,width,height] in pixel coordinates. The rows represent the coordinates of each bounding box, where M represents the number of blobs.
For example, there are two blobs, where x and y define the location of the upperleft corner of the bounding box, and w and 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.
To enable this port, select the Bounding Box parameter.
Main Tab
Area
— Number of pixels in labeled regionsNumber of pixels in labeled regions, returned as a vector.
To enable this port, select the Area parameter.
Data Types: int32
Centroid
— Centroid coordinatesMby2 matrix of M number of blobs.
The rows represent the coordinates of the centroid of each region, and M represents the number of blobs.
For example, there are two blobs where the row and column coordinates of their centroids are x_{1}, y_{1} and x_{2}, y_{2}. The block outputs:
$$\left[\begin{array}{cc}{x}_{1}& {y}_{1}\\ {x}_{2}& {y}_{2}\end{array}\right]$$
at the Centroid port.
To enable this port, select the Centroid parameter.
Data Types: double
 single
 fixed point
BBox
— Bounding box coordinatesBounding box coordinates, returned as an Mby4 matrix of M bounding boxes for blobs. Each row of the matrix defines a bounding box as a fourelement vector [x,y,width,height] in pixel coordinates. The rows represent the coordinates of each bounding box, where M represents the number of blobs.
For example, there are two blobs, where x and y define the location of the upperleft corner of the bounding box, and w and 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.
To enable this port, select the Bounding Box parameter.
Major axis length
— Length of major axis of ellipsesEnables the Major axis length port. Select this check box to output a vector that
Represents the lengths of the major axes of ellipses
Has the same normalized second central moments as the labeled regions
Data Types: double
 single
Minor axis length
— Length of minor axis of ellipsesEnables the Minor axis length port. Select this check box to output a vector that
Represents the lengths of the minor axes of ellipses
Has the same normalized second central moments as the labeled regions
Data Types: double
 single
Orientation
— OrientationEnables the Orientation port.
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}$$ inclusive.
Data Types: double
 single
Eccentricity
— EccentricityEnables the Eccentricity port. Select this check box to output a vector that represents the eccentricities of ellipses that have the same second moments as the region.
Data Types: double
 single
Equivalent diameter squared
— Equivalent diameter squaredEnables the Equivalent diameter squared port. Select this check box to output a vector that represents the equivalent diameters squared.
Data Types: double
 single
 fixed point
Extent
— ExtentEnables the Extent port. 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.
Data Types: double
 single
 fixed point
Perimeter
— Perimeter lengthEnables the Perimeter port. 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.
Data Types: double
 single
 fixed point
Statistics output data type
— Output data typeSpecify the data type of the outputs as double
,
single
, or Specify via Data Types
tab
.
Data Types: double
 single
Connectivity
— Number of labeled regions8
(default)  4
Specify the number of labeled regions in each image.
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 other pixels on the top, bottom, left, right, and diagonally, select
8
. For more information about this parameter, see the
Label block.
The Connectivity parameter also affects how the block
calculates the perimeter of a blob. For example, this 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}$$.
Data Types: double
 single
Output label matrix
— Output label matrixEnable the Label port. Select this check box to output the
label matrix. 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.
Blob Properties Tab
Maximum number of blobs
— Maximum number of blobsSpecify 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 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
— Warn if maximum number of blobs is exceededSelect this parameter to warn if maximum number of blobs is exceeded.
Output actual number of blobs
— Number of blobsEnable the Count port. Select this parameter to output a scalar value that represents the actual number of connected regions in each image.
Specify minimum blob area in pixels
— Minimum blob area in pixels0
(default)  scalarSelect this parameter to specify the minimum blob area in pixels. The blob is labeled if the number of pixels meets the minimum size specified.
Tunable: Yes
Specify maximum blob area in pixels
— Maximum blob area in pixelsSelect this parameter to specify the maximum blob area in pixels. The blob is
labeled if the number of pixels meets the maximum size specified. The maximum allowable
value is the maximum of the uint32
data type.
Tunable: Yes
Exclude blobs touching image border
— Exclude blobs touching image borderSpecify this parameter to exclude a labeled blob that contains at least one border pixel.
Output blob statistics as a variable size signal
— Output blob statistics as a variable size signalSpecify this parameter to output blob statistics as a variablesize signal.
Fill empty spaces in output
— Fill empty spaces in outputSpecify this parameter to fill empty spaces in the statistical vectors with the values you specify in the Fill values parameter.
To enable this parameter, clear the Output blob statistics as a variable size signal parameter.
Fill values
— Scalar used to fill empty spaces in output1
(default)  scalar  vectorSpecify a scalar value to fill all the empty spaces in the statistical vectors. 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 clear the Fill empty spaces in outputs parameter.
To enable this parameter, clear the Output blob statistics as a variable size signal parameter.
Data Types Tab
To enable option on the Data Types Tab tab, in the
Main tab, set the Select output data type
parameter to Specify via Data Types tab
. For details on the fixedpoint
block parameters, see Specify FixedPoint Attributes for Blocks.
Data Types 

Multidimensional Signals 

VariableSize Signals 

^{[a]} Generated code will be restricted to MATLAB host computers when you set the FFT implementation parameter to FFTW, or when the transform length is not a power of two. ^{[b]} This data type is supported at the output port(s). ^{[c]} Fixedpoint data types are not supported at the Major Axis, Minor Axis, Orientation, and Eccentricity output ports. 
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
Select web siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.