ImFusion C++ SDK 4.5.0
ImFusion::ConnectivityAnalysis Namespace Reference

Set of functions for efficient connectivity analysis of binary or thresholded images. More...

Detailed Description

Set of functions for efficient connectivity analysis of binary or thresholded images.

This namespace provides optimized implementations for identifying and labeling connected components in 2D and 3D images. Both CPU and GPU implementations are available for both 2D and 3D images.

Enumerations

enum  Connectivity {
  CONNECT4_2D = 4 , CONNECT8_2D = 8 , CONNECT6_3D = 6 , CONNECT18_3D = 18 ,
  CONNECT26_3D = 26
}
 Connectivity types for 2D and 3D connected component analysis. More...

Functions

template<typename T, typename S>
int computeConnectedComponents (const TypedImage< T > *inImage, TypedImage< S > *labelImage, Connectivity connectivity, int minComponentSize=-1, int maxNumberComponents=-1, T threshold=T(1), int maxComponentSize=-1, std::vector< size_t > *componentSizes=nullptr)
 Compute connected components of the input image using a CPU-based implementation.
template<typename S>
int computeConnectedComponents (GlImage *inImage, TypedImage< S > *labelImage, Connectivity connectivity, int minComponentSize=-1, int maxNumberComponents=-1, double threshold=1.0, int maxComponentSize=-1, std::vector< size_t > *componentSizes=nullptr)
 Compute connected components of the input image using a GPU-accelerated implementation.
template<typename T, typename S>
int hysteresisThresholding (TypedImage< T > *inImage, TypedImage< S > *labelImage, double lowThreshold, double highThreshold, Connectivity connectivity, int minComponentSize=-1, int maxNumberComponents=-1)

Enumeration Type Documentation

◆ Connectivity

Connectivity types for 2D and 3D connected component analysis.

Defines the neighborhood structure used to determine if pixels/voxels belong to the same component:

  • 2D: 4-connectivity (face neighbors) or 8-connectivity (face + diagonal neighbors)
  • 3D: 6-connectivity (face neighbors), 18-connectivity (face + edge neighbors), or 26-connectivity (face + edge + corner neighbors)
Enumerator
CONNECT4_2D 

2D connectivity using 4 face neighbors

CONNECT8_2D 

2D connectivity using 8 face and diagonal neighbors

CONNECT6_3D 

3D connectivity using 6 face neighbors

CONNECT18_3D 

3D connectivity using 18 face and edge neighbors

CONNECT26_3D 

3D connectivity using 26 face, edge, and corner neighbors

Function Documentation

◆ computeConnectedComponents() [1/2]

template<typename T, typename S>
int ImFusion::ConnectivityAnalysis::computeConnectedComponents ( const TypedImage< T > * inImage,
TypedImage< S > * labelImage,
Connectivity connectivity,
int minComponentSize = -1,
int maxNumberComponents = -1,
T threshold = T(1),
int maxComponentSize = -1,
std::vector< size_t > * componentSizes = nullptr )

Compute connected components of the input image using a CPU-based implementation.

Identifies and labels all connected components in the input image using an optimized union-find algorithm. All pixels with a value greater than or equal to the specified threshold are considered foreground and processed. Components can be filtered by size and total count. The resulting label image assigns each pixel a unique component ID (starting from 1), with larger components receiving lower IDs. Background pixels are labeled as 0.

Parameters
inImageInput image to analyze, will not be modified
labelImageOutput image to store component labels; must have the same dimensions as the input image
connectivityType of connectivity to use (4 or 8 for 2D images, 6, 18, or 26 for 3D images)
minComponentSizeMinimum component size in pixels/voxels; components smaller than this will be removed (-1 = no filtering)
maxNumberComponentsMaximum number of components to keep, sorted by size (-1 = keep all)
thresholdThreshold value; pixels >= threshold are considered foreground
maxComponentSizeMaximum component size in pixels/voxels; components larger than this will be removed (-1 = no filtering)
componentSizesOptional output vector to receive component sizes; index i contains the size of component label i+1
Returns
Number of components found after filtering, or -1 on error

◆ computeConnectedComponents() [2/2]

template<typename S>
int ImFusion::ConnectivityAnalysis::computeConnectedComponents ( GlImage * inImage,
TypedImage< S > * labelImage,
Connectivity connectivity,
int minComponentSize = -1,
int maxNumberComponents = -1,
double threshold = 1.0,
int maxComponentSize = -1,
std::vector< size_t > * componentSizes = nullptr )

Compute connected components of the input image using a GPU-accelerated implementation.

Identifies and labels all connected components in the input image using GPU compute shaders. All pixels with a value greater than or equal to the specified threshold are considered foreground and processed. Components can be filtered by size and total count. The resulting label image assigns each pixel a unique component ID (starting from 1), with larger components receiving lower IDs. Background pixels are labeled as 0. Note: The underlying algorithm is inherently hard to parallelize, so the GPU implementation might be slower than the CPU implementation for small images.

Parameters
inImageGPU image to analyze; must be a valid GlImage with texture data
labelImageOutput image to store component labels; must have the same dimensions as the input image
connectivityType of connectivity to use (4 or 8 for 2D images, 6, 18, or 26 for 3D images)
minComponentSizeMinimum component size in pixels/voxels; components smaller than this will be removed (-1 = no filtering)
maxNumberComponentsMaximum number of components to keep, sorted by size (-1 = keep all)
thresholdThreshold value; pixels >= threshold are considered foreground
maxComponentSizeMaximum component size in pixels/voxels; components larger than this will be removed (-1 = no filtering)
componentSizesOptional output vector to receive component sizes; index i contains the size of component label i+1
Returns
Number of components found after filtering, or -1 on error
Note
Requires OpenGL 4.3+ support for compute shaders
Image type DOUBLE is not supported on GPU

◆ hysteresisThresholding()

template<typename T, typename S>
int ImFusion::ConnectivityAnalysis::hysteresisThresholding ( TypedImage< T > * inImage,
TypedImage< S > * labelImage,
double lowThreshold,
double highThreshold,
Connectivity connectivity,
int minComponentSize = -1,
int maxNumberComponents = -1 )
Deprecated
This function is deprecated and will be removed in a future release.
Deprecated
"Hysteresis thresholding was removed from ConnectivityAnalysis."
Search Tab / S to search, Esc to close