IDS peak ICV v1.5.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 guide covers the core operations for extracting, modifying, and analyzing regions.

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:

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

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:

  • C++
    peak::icv::Region regionIntersection = regionA.Intersection(regionB);
  • C#
    using var regionIntersection = regionA.Intersection(regionB);
  • Python
    region_intersection = region_A.intersection(region_B)

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:

  • C++
    peak::icv::Region regionDifference = regionA.Difference(regionB);
  • C#
    using var regionDifference = regionA.Difference(regionB);
  • Python
    region_difference = region_A.difference(region_B)

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:

  • C++
    peak::icv::Region regionUnion = regionA.Union(regionB);
  • C#
    using var regionUnion = regionA.Union(regionB);
  • Python
    region_union = region_A.union(region_B)

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.

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

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.

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