Image Connected Component Analysis

Description

This operator performs connected component analysis on input binary images, identifying all independent white pixel regions in the image as connected components. For each identified connected component, the operator can output its contour, center point, and an independent mask image, and filter results based on area size.

Overview

Identifies connected components in the input binary image, outputting their contours, center points, and independent mask images, with optional filtering by area size.

Scenarios

  • Object Detection and Segmentation: Separating each independent object instance to obtain their positions and contours.

  • Noise Removal: Effectively removing small-area noise points generated after binarization through area filtering.

  • Defect Detection: Detecting defects such as scratches, stains, and pits on product surfaces. Defects usually form independent connected regions after binarization.

Inputs and Outputs

Inputs

Binary image: One or more binary images.

Outputs

Detection Results: A list of detection results, where each element represents a detected connected component, containing information such as the contour, category, and confidence of the region.

Result center point list: A list containing the coordinates [x, y] of the center points of each identified connected component that passed the area filtering.

Result mask images: Only when the parameter "Return Mask List" is enabled, this port outputs a list of binary images. Each image in the list corresponds to a detected connected component, where the region is white and the rest is black.

Parameters

Result Type

Description

Sets the representation format for the contour of each detected object.

Tuning Instructions

  • Minimum bounding box (default): The operator computes the minimum-area rectangle that completely encloses each connected component. This method is fast and produces regular results, suitable for most scenarios where only an approximate position and size of the target are needed.

  • Mask: The operator extracts the precise contour of each connected component, forming a potentially irregular polygon. Suitable for scenarios requiring accurate shape analysis or area calculation, but involves slightly higher computational cost and may produce a very large number of contour points.

Parameter Range

Values/Range:

  • Polygon

  • Minimum bounding rectangle

Default: Minimum bounding rectangle

Connectivity Type

Description

Defines the rule used to determine which neighboring pixels are considered "connected" in an image. The two common methods are 4-connectivity and 8-connectivity.

Tuning Instructions

  • 8-connectivity: A pixel is considered a neighbor of all 8 surrounding pixels (top, bottom, left, right, and the 4 diagonal directions). This is the more commonly used setting. If two white regions touch only at a corner point, this mode will treat them as a single connected object.

  • 4-connectivity: A pixel is considered a neighbor of only its 4 adjacent pixels (top, bottom, left, and right). In this mode, two regions that touch only at a corner point will be treated as two separate objects.

Parameter Range

Values/Range:

  • 4-Connectivity

  • 8-Connectivity

Default: 8-Connectivity

Minimum Pixel Area

Description

Sets an area threshold. All connected components whose pixel count (area) is smaller than this value will be filtered out.

Tuning Instructions

After binarization, small white speckles caused by noise frequently appear in the image. By setting an appropriate minimum area, these meaningless noise points can be removed. When tuning, observe the approximate pixel area of normal targets in the binary image, and set this parameter to a value smaller than the smallest normal target but larger than most noise.

For example, if the area of normal targets is always above 200 pixels and noise points are generally below 50 pixels, this value can be set to 100.

Parameter Range

[5, 1000000], default value: 100

Parameter Range

Values/Range: [5, 1000000]

Default: 100

Maximum Pixel Area

Description

Sets an area threshold. All connected components whose pixel count (area) is larger than this value will be filtered out.

Tuning Instructions

This parameter can be used to exclude abnormally large regions. For example, if improper lighting or threshold settings cause a large portion of the background to be incorrectly identified as a white region, this parameter can be used to filter it out. Typically, this value can be set to something considerably larger than the maximum area that a normal target could possibly occupy.

Parameter Range

[5, 10000000], default value: 300000

Parameter Range

Values/Range: [5, 10000000]

Default: 300000

Return Mask List

Description

Controls whether to generate and output an independent mask image for each detected connected component.

Tuning Instructions

  • Disabled (Default): Does not generate a list of independent mask images; the output is empty. This method saves more memory and computational resources and is suitable for the vast majority of application scenarios that only require contours and center points.

  • Enabled: Generates an independent binary mask image of the same size as the original image for each filtered connected component and combines them into a list output. Enable this option only when subsequent operators explicitly require this input.

Parameter Range

Default: False