IDS peak ICV v1.1.0
Loading...
Searching...
No Matches
Working with Regions

In many image processing tasks, it's essential to identify and analyze specific areas within an image. Such an area is called a region. A region typically consists of connected pixels that share certain properties or spatial relationships.

This section introduces operations for working with such regions, including:

  • Identifying connected components (e.g., separating distinct shapes or objects)
  • Applying set operations such as intersection and difference to compare or modify regions
  • Calculating basic region properties, like area or center of gravity, to support further analysis

Determining connected components

If you want to identify connected components of a region you determine which pixels are connected to each other. Two pixels are considered connected if they have an edge or a corner in common. This connectivity is called 8-neighborhood.

8-neighborhood

To obtain the individual components of a region, use the following function:

  • Python
    regions_connected = region.connected_components
  • C++
    std::vector<peak::icv::Region> regionsConnecetd = region.GetConnectedComponents();

After determining the connected components, the individual components are stored as an array of regions.

Two Regions

Applying set operations to regions

Regions can be changed using various mathematical set operations. You can use these set operations to perform changes and analyses on regions, which is useful for various image processing and computer vision tasks.

These operations include intersection, difference and union.

Determining the intersection

The intersection of two regions, A and B, consists of all points that are common to both regions. A ⋂ B represents the overlapping area where the red square and the green rectangle intersect.

A B A ⋂ B

Use the following function:

Determining the difference

The difference between two regions, A and B, consists of all points that belong to region A but not to region B. As shown below, A \ B represents the area of the red square excluding the part that overlaps with the green rectangle.

A B A \ B

Conversely, B \ A represents the area of the green rectangle excluding the part that overlaps with the red square.

B A B \ A

Use the following function:

Determining the union

The union of two regions, A and B, consists of all points that belong to region A and region B.

B A B ⋃ A

Use the following function:

Determining features of a region

You can determine the following properties of a region, which we call features:

  • Area
  • Center of gravity

Area

One basic feature is the area, which corresponds to the number of points in the region.

  • Python
    area = region.area
  • C++
    size_t area = region.GetArea();

Center of Gravity

The center of gravity of a region is calculated as the average of the coordinates of all its points, indicating the region’s central position. The result is subpixel precise, meaning it is not limited to integer coordinates.

  • Python
    center_of_gravity = region.center_of_gravity
  • C++
    peak::common::PointF center_of_gravity = region.GetCenterOfGravity();