SortBlobs

SortBlobs is used to sort the blobs referenced in a Blobls data structure in relation to a fixture.

By computing the position of the referenced blob's center of mass (centroid) relative to the specified image fixture coordinate system, SortBlobs sorts the referenced blobs based upon one of their measurement characteristics, such as the blob's distance along the x or y-axis, from a fixture origin or a grid, or the blob's angle or angular distance.

Each blob in the referenced Blobs data structure is examined, and depending upon the Sort By parameter setting, the blob is identified and its position is calculated by measuring either the blob's distance or angular relationship to a fixed location.

Once SortBlobs has sorted the referenced blobs, a new Blobs data structure and accompanying result table will be automatically inserted into the spreadsheet. The result table is sorted by how close the blob is to the chosen fixture, in descending order (the closest blob will be listed first, the next closest second, etc.).

SortBlobs is an extremely helpful function in instances where there are multiple blobs and the position of each blob in relation to the other blobs needs to be determined.

SortBlobs Inputs

Syntax: SortBlobs (Blobs,Number to Sort,Sort By,Fixture.Row,Fixture.Column,Fixture.Theta,Show)

Parameter Description

Blobs

This parameter references the spreadsheet cell that contains the Blobs data structure that is to be sorted. For more information, see Cell References - Relative/Absolute.

Number to Sort

Specifies the maximum number of blobs (1 to 4096; default = 3) to return.

Note: If the value of this parameter is greater than zero, SortBlobs will automatically insert a result table containing a maximum of 10 entries that correspond to the first 10 blobs in the Blobs data structure. If you wish to display more entries, you can expand the table by copying the last row and pasting additional rows at the end; make sure to increment the index number of any newly-pasted row so that the proper blob is indexed.

Sort By

Specifies how the referenced blobs will be measured and sorted.

0 = X (default)

Sort by distance along the x-axis, from closest to furthest, in descending order.

ClosedEXAMPLE

 

1 = Y

Sort by distance along the y-axis, from closest to furthest, in descending order.

ClosedEXAMPLE

 

2 = Angle

Sort by the angle (0 to 360 degrees), as measured from the x-axis of the fixture coordinate system to the line segment defined by the blob's centroid (center of mass) and the fixture origin, from closest to furthest, in descending order.

ClosedEXAMPLE

 

3 = Angular Distance

Sort by the absolute value of the angle (-180 to 180 degrees), as measured from the x-axis of the fixture coordinate system to a line segment defined by the blob centroid and the fixture origin, from closest to furthest, in descending order.

ClosedEXAMPLE

 

4 = Distance

Sort by the distance from the fixture origin to the blob's centroid, from closest to furthest, in descending order.

ClosedEXAMPLE

 

5 = Grid X

Sort by distance along the fixture's x-axis first, and then by distance along the y-axis, from closest to furthest, in descending order.

Note: SortBlobs will return #ERR if Grid X is selected and the function is referencing an image that has been calibrated to world coordinate values, such as a CalibrateImage or TransBlobsToWorld function's output. Grid X sorting can only be applied to pixel coordinates. To use the Grid X sorting method using world coordinates, the ExtractBlobs function being referenced by the SortBlobs function should reference the output of a TransformImage function, with the SortBlobs function sorting in pixel coordinates. The output data can then be transformed to world coordinates using the TransBlobsToWorld function. For more information, see ExtractBlobs and TransformImage.

ClosedEXAMPLE

 

6 = Grid Y

Sort by distance along the fixture's y-axis first, and then by distance along the x-axis, from closest to furthest, in descending order.

Note: SortBlobs will return #ERR if Grid Y is selected and the function is referencing an image that has been calibrated to world coordinate values, such as a CalibrateImage or TransBlobsToWorld function's output. Grid Y sorting can only be applied to pixel coordinates. To use the Grid Y sorting method using world coordinates, the ExtractBlobs function being referenced by the SortBlobs function should reference the output of a TransformImage function, with the SortBlobs function sorting in pixel coordinates. The output data can then be transformed to world coordinates using the TransBlobsToWorld function. For more information, see ExtractBlobs and TransformImage.

ClosedEXAMPLE

 

7 = Width

Sorts by width values, from the largest to the smallest.

Note:
  • The In-Sight 5605 vision system does not support this parameter option.
  • On the In-Sight 5604 vision system, the Width and Height options are swapped, i.e. Width = 8 and Height = 7.

8 = Height

Sorts by height values, from the largest to the smallest.

Note:
  • The In-Sight 5605 vision system does not support this parameter option.
  • On the In-Sight 5604 vision system, the Width and Height options are swapped, i.e. Width = 8 and Height = 7.

Fixture

Defines the referenced blob's center of mass (centroid) relative to a Fixture input or the output of a Vision Tool function's image coordinate system. Setting the referenced blob's center of mass relative to a Fixture ensures that if the Fixture is rotated or translated, the referenced blob will be rotated or translated in relation to the Fixture. For more information, see Fixture.

The default setting is (0,0,0), the top leftmost corner of the image.

Row

The row offset, in image coordinates.

Column

The column offset, in image coordinates.

Theta

The angle of orientation, in the image coordinate system.

Show

Specifies the display mode for SortBlobs graphical overlays on top of the image.

0 = hide all (default)

All graphics will be hidden, except when the cell containing the SortBlobs function is highlighted in the spreadsheet.

1 = result graphics only

Blob outlines will be displayed at all times.

SortBlobs Outputs

Returns

A Blobs data structure containing the sorted blobs, or #ERR if any of the input parameters are invalid.

Results

When SortBlobs is initially inserted into a cell, a result table is created in the spreadsheet.

Note: If the value of the Number to Sort parameter is greater than zero, SortBlobs will automatically insert a result table containing a maximum of 10 entries that correspond to the first 10 blobs in the Blobs data structure. If you wish to display more entries, you can expand the table by copying the last row and pasting additional rows at the end; make sure to increment the index number of any newly-pasted row so that the proper blob is indexed.

SortBlobs Vision Data Access Functions

The following Vision Data Access functions are automatically inserted into the spreadsheet to create the SortBlobs Blobs data structure result table. For more information, see Blobs.

Spreadsheet Name Function Name Description

Row

GetRow(Blobs, Blob Index)

Returns the y-coordinate (Row) of the referenced blob's center of mass (centroid).

ClosedEXAMPLE

Col

GetCol(Blobs, Blob Index)

Returns the x-coordinate (Column) of the referenced blob's center of mass (centroid).

ClosedEXAMPLE

Angle

GetAngle(Blobs, Blob Index)

Returns the angle of the referenced blob's center of mass, relative to the center of the ROI.

ClosedEXAMPLE

Color

GetColor(Blobs, Blob Index)

Returns the color value (0 = black, 1 = white) of the referenced blob.

Score

GetScore(Blobs, Blob Index)

A measure of how closely the blob matches the criteria of a FindBlobs function. For more information, see FindBlobs.

Area

GetArea(Blobs, Blob Index)

Returns the area of the referenced blob (measured in pixels).

ClosedEXAMPLE

Note: If there are holes in the blob, the Area value will vary depending on whether or not the Fill Holes checkbox is enabled or disabled. For more information, see Fill Holes.

Elongation

GetElongation(Blobs, Blob Index)

Returns a value that represents how the referenced blob's pixels are stretched out from the blob's center of mass (centroid). For instance, a circle would report 0 Elongation, while a nail would have a high Elongation value.

ClosedEXAMPLE

Holes

GetHoles(Blobs, Blob Index)

Returns the number of holes contained within the referenced blob.

Perimeter

GetPerimeter(Blobs, Blob Index)

Returns the length of the boundary around the referenced blob; the perimeter is calculated by counting the external edges of the pixels that form the boundary of the blob.

ClosedEXAMPLE

Spread

GetSpread(Blobs, Blob Index)

Returns a value that represents how the referenced blob's pixels are distributed away from the blob's center of mass (centroid). For instance, a circular shaped object would have a lower Spread value than an oval shaped object.

ClosedEXAMPLE

Additional data elements can be accessed using the following Vision Data Access functions:

Thresh

GetThresh(Blobs)

The Threshold value that was used to segment the image.

NFound

GetNFound(Blobs)

The number of blobs found.

MinRow

GetMinRow(Blobs, Blob Index)

Returns the topmost row coordinate for a square bounding box around the referenced blob, oriented to the image coordinate frame.

Note: For an alternative bounding box, with a varied orientation, see BoundingRectangle.

MinCol

GetMinCol(Blobs, Blob Index)

Returns the leftmost column coordinate for a square bounding box around the referenced blob, oriented to the image coordinate frame.

Note: For an alternative bounding box, with a varied orientation, see BoundingRectangle.

MaxRow

GetMaxRow(Blobs, Blob Index)

Returns the bottommost row coordinate for a square bounding box around the referenced blob, oriented to the image coordinate frame.

Note: For an alternative bounding box, with a varied orientation, see BoundingRectangle.

MaxCol

GetMaxCol(Blobs, Blob Index)

Returns the leftmost column coordinate for a square bounding box around the referenced blob, oriented to the image coordinate frame.

Note: For an alternative bounding box, with a varied orientation, see BoundingRectangle.

SortBlobs Example

The SortBlobs function is used to sort the blobs referenced in a Blobs data structure based on the referenced blobs' distance from a fixture. This example will help to illustrate how the SortBlobs parameter settings can be used to sort a set of blobs based upon their position relative to a fixture.

A SortBlobs function was inserted into an empty cell in the spreadsheet, automatically launching the SortBlobs property sheet.

In this example, the parameters are being set to sort the blobs identified in the earlier DetectBlobs example, using the blob returned by the FindBlobs example as a fixture. For more information, see FindBlobs.

Based upon these requirements, the SortBlobs parameters would be configured as follows:

  • Blobs: This parameter was set as an absolute cell reference to the previously created DetectBlobs Blobs data structure.
  • Number to Sort: This parameter was set to 6 because there are 6 known blobs that are being sorted.
  • Sort By: This parameter was set to distance - From the Fixture origin. By choosing this parameter setting, the Fixture parameter will need to be set to determine the starting point for the measurements.
  • Fixture: This parameter was set as cell references to the Row and Column coordinates returned in the FindBlobs example's Blobs data structure. By choosing this parameter setting, this ensures that the measurements and sorting will always originate from the specified feature in the image. It's possible to use another feature in the image, such as an edge, a point or another blob. For instance, in this example, the blob that was returned from the FindBlobs example will be used to set the Fixture coordinates.
  • Show: The default setting was used, which only allows the result graphics to be displayed when the cell containing the Blobs data structure is selected, as in the example below.

After configuring the SortBlobs property sheet, a Blobs data structure and result data table are produced: