| Customize Help

Finding the blob location and its bounding box



Finding the location of blobs in an image can sometimes be more useful than finding their shape or size. For example, if a robotic arm needs to pick up several items regardless of their type, it can use their location in an acquired image to determine their actual physical position.

You can also use the blob location to determine if a blob touches any side of the image border. If there are any such blobs, you might want to adjust the camera's field of view so that all items are completely represented in the image, or you might want to exclude these blobs.

Points of the bounding box aligned with the pixel coordinate system

You can determine the blob's points of contact with the blob's bounding box aligned with the pixel coordinate system. To do so, enable the M_BOX, M_CONTACT_POINTS, and M_CENTER_OF_GRAVITY groups of features for calculation using MblobControl(). Use MblobGetResult() with the constants below to retrieve the corresponding point of contact after calculation.

Note that for the blob in the image below, there are at least two possible ways to determine each of its contact points. This is because there is only one point of contact on each side of the blob's border. For example:

Legend

A1

(M_BOX_X_MIN, M_BOX_Y_MIN)

A2

(M_BOX_X_MAX, M_BOX_Y_MIN)

B1

(M_BOX_X_MIN, M_Y_MIN_AT_X_MIN)

B2

(M_BOX_X_MAX, M_Y_MIN_AT_X_MAX)

C1

(M_BOX_X_MIN, M_Y_MAX_AT_X_MIN)

C2

(M_BOX_X_MAX, M_Y_MAX_AT_X_MAX)

D1

(M_BOX_X_MIN, M_BOX_Y_MAX)

D2

(M_BOX_X_MAX, M_BOX_Y_MAX)

E1

(M_X_MIN_AT_Y_MIN, M_BOX_Y_MIN) OR

(M_FIRST_POINT_X, M_FIRST_POINT_Y)

E2

(M_X_MIN_AT_Y_MAX, M_BOX_Y_MAX)

F1

(M_X_MAX_AT_Y_MIN, M_BOX_Y_MIN)

F2

(M_X_MAX_AT_Y_MAX, M_BOX_Y_MAX)

G

(M_CENTER_OF_GRAVITY_X, M_CENTER_OF_GRAVITY_Y)

In contrast, if there are multiple points of contact on one side of the blob border, each point of contact will be named differently, as shown in the image below.

The center of gravity can be calculated in binary or grayscale mode. To calculate the latter, you must provide MblobCalculate() with a grayscale image.

Minimum-area and minimum-perimeter bounding box points

Besides points established from a blob's bounding box aligned with the pixel coordinate system, you can establish points from the minimum-area or the minimum-perimeter bounding box of the blob. To calculate the bounding box that has the least area, use the M_MIN_AREA_BOX group of features; whereas to calculate the bounding box that has the smallest perimeter, use the M_MIN_PERIMETER_BOX group of features. These groups of features are enabled for calculation using MblobControl(). Use MblobGetResult() with the following constants to retrieve them after calculation:

Area Box Legend

Perimeter Box Legend

A1

(M_MIN_AREA_BOX_Xn, M_MIN_AREA_BOX_Yn) 1

A2

(M_MIN_PERIMETER_BOX_Xn, M_MIN_PERIMETER_BOX_Yn) 1

B1

(M_MIN_AREA_BOX_CENTER_X, M_MIN_AREA_BOX_CENTER_Y)

B2

(M_MIN_PERIMETER_BOX_CENTER_X, M_MIN_PERIMETER_BOX_CENTER_Y)

C1

M_MIN_AREA_BOX_WIDTH

C2

M_MIN_PERIMETER_BOX_WIDTH

D1

M_MIN_AREA_BOX_HEIGHT

D2

M_MIN_PERIMETER_BOX_HEIGHT

E1

M_MIN_AREA_BOX_ANGLE

E2

M_MIN_PERIMETER_BOX_ANGLE

1 n stands for an integer from 1 to 4.

Note that the width of the box is always the longer of the two sides. The angle of the minimum-area or minimum-perimeter bounding box is always measured from the X-axis to the side from which the width of the minimum-area or minimum-perimeter box is measured.

Points with respect to the relative world coordinate system

When working with calibrated images, you can retrieve the above-mentioned points with respect to the relative coordinate system, by calling MblobControl() with M_RESULT_OUTPUT_UNITS set to M_WORLD. However, in this case, the above-mentioned points are calculated in the pixel coordinate system and then the coordinates of these points are converted to the relative coordinate system.

To calculate the blob's bounding box and contact points in the relative coordinate system, you must enable the calculation of the M_WORLD_BOX group of features using MblobControl(); then, use MblobGetResult() with the following constants to retrieve them after calculation:

Legend

A1

(M_WORLD_BOX_X_MIN, M_WORLD_BOX_Y_MIN)

A2

(M_WORLD_BOX_X_MAX, M_WORLD_BOX_Y_MIN)

B1

(M_WORLD_BOX_X_MIN, M_WORLD_Y_AT_X_MIN)

B2

(M_WORLD_BOX_X_MAX, M_WORLD_Y_AT_X_MAX)

C1

(M_WORLD_BOX_X_MIN, M_WORLD_BOX_Y_MAX)

C2

(M_WORLD_BOX_X_MAX, M_WORLD_BOX_Y_MAX)

D1

(M_WORLD_X_AT_Y_MIN, M_WORLD_BOX_Y_MIN)

D2

(M_WORLD_X_AT_Y_MAX, M_WORLD_BOX_Y_MAX)

Chained pixels

You can obtain the coordinates of pixels bordering blobs or delimiting holes in blobs, in a counterclockwise or clockwise direction, respectively. These pixels are referred to as chained pixels. To calculate these pixels, enable the M_CHAINS group of features for calculation using MblobControl().

You can use the chained pixel coordinates to create a chain code. A chain code is a directional code that records an object's boundary as a discrete set of vectors, where each vector points to the next pixel in the chain.

Chained pixels always form a closed chain. This implies that the starting pixel in the chain is also the closing one. If your blob has regions which are 1 pixel wide, these pixels are chained twice, once in the forward direction and then in the opposite direction.

In the diagram below, the thick lines illustrate pixels that are chained twice. The diagram also illustrates chained pixels of a blob in an 8 and 4-connected lattice, where the solid lines illustrate chained pixels in an 8-connected lattice, and the dotted lines illustrate how chained pixels deviate in a 4-connected lattice. Also, note that the blob's outermost chain is identified as index 1. Chains that delimit holes in blobs are identified by subsequent indices.

The M_CHAINS feature group enables five separate chain features for calculation. This allows you to retrieve the following feature results using MblobGetResult():

When retrieving results for chain features, get the results for the number of chained pixels, in total or in a particular blob first (M_TOTAL_NUMBER_OF_CHAINED_PIXELS or M_NUMBER_OF_CHAINED_PIXELS respectively). This allows you to allocate an array that is large enough for the other chain results.

For the blob shown above, you would get the following results:

Chain index

Chain-X

Chain-Y

1

4

2

1

4

3

1

4

4

1

4

5

...

...

...

2

5

5

2

6

5

2

7

5

2

8

5

As mentioned, blobs with holes have multiple chains.

To determine the chain to which a pixel coordinate (M_CHAIN_X and M_CHAIN_Y) belongs, use MblobGetResult() with M_CHAIN_INDEX.