Class HfsSegment
- Namespace
- OpenCvSharp.Hfs
- Assembly
- OpenCvSharp.dll
Hierarchical Feature Selection for Efficient Image Segmentation.
This algorithm is executed in 3 stages: first, the SLIC (simple linear iterative clustering) algorithm is used to obtain the superpixels of the input image. Second, each superpixel is viewed as a node in a graph, and the EGB (Efficient Graph-based Image Segmentation) algorithm is used to merge some of the nodes, obtaining a coarser segmentation, followed by a post process that merges small regions into their nearby region. Third, the algorithm exploits a similar mechanism to further merge the small regions obtained in the second stage into an even coarser segmentation.
public class HfsSegment : Algorithm, IDisposable
- Inheritance
-
HfsSegment
- Implements
- Inherited Members
Properties
MinRegionSizeI
This parameter is used in the second stage. After the EGB segmentation, regions that have fewer pixels than this parameter will be merged into its adjacent region.
public int MinRegionSizeI { get; set; }
Property Value
MinRegionSizeII
This parameter is used in the third stage. It serves the same purpose as MinRegionSizeI.
public int MinRegionSizeII { get; set; }
Property Value
NumSlicIter
This parameter is used in the first stage. It describes how many iterations to perform when executing SLIC.
public int NumSlicIter { get; set; }
Property Value
SegEgbThresholdI
This parameter is used in the second stage. It is a constant used to threshold weights of the edge when merging adjacent nodes when applying EGB algorithm. The segmentation result tends to have more regions remained if this value is large and vice versa.
public float SegEgbThresholdI { get; set; }
Property Value
SegEgbThresholdII
This parameter is used in the third stage. It serves the same purpose as SegEgbThresholdI.
public float SegEgbThresholdII { get; set; }
Property Value
SlicSpixelSize
This parameter is used in the first stage (the SLIC stage). It describes the size of each superpixel when initializing SLIC. Every superpixel approximately has slicSpixelSize x slicSpixelSize pixels in the beginning.
public int SlicSpixelSize { get; set; }
Property Value
SpatialWeight
This parameter is used in the first stage (the SLIC stage). It describes how important the role of position is when calculating the distance between each pixel and its center. The exact formula to calculate the distance is colorDistance + spatialWeight * spatialDistance. The segmentation result tends to have more local consistency if this value is larger.
public float SpatialWeight { get; set; }
Property Value
Methods
Create(int, int, float, int, float, int, float, int, int)
Creates a HfsSegment object.
public static HfsSegment Create(int height, int width, float segEgbThresholdI = 0.08, int minRegionSizeI = 100, float segEgbThresholdII = 0.28, int minRegionSizeII = 200, float spatialWeight = 0.6, int slicSpixelSize = 8, int numSlicIter = 5)
Parameters
heightintthe height of the input image.
widthintthe width of the input image.
segEgbThresholdIfloatparameter segEgbThresholdI.
minRegionSizeIintparameter minRegionSizeI.
segEgbThresholdIIfloatparameter segEgbThresholdII.
minRegionSizeIIintparameter minRegionSizeII.
spatialWeightfloatparameter spatialWeight.
slicSpixelSizeintparameter slicSpixelSize.
numSlicIterintparameter numSlicIter.
Returns
PerformSegmentCpu(InputArray, bool)
Do segmentation with the CPU. This method is only implemented for reference; it is highly not recommended to use it.
public virtual Mat PerformSegmentCpu(InputArray src, bool ifDraw = true)
Parameters
srcInputArraythe input image.
ifDrawboolif true, the returned Mat is a segmented picture where the color of each region is the average color of all pixels in that region, and its data type is the same as the input image. If false, the content of the returned Mat is a matrix of indices describing the region each pixel belongs to, and its data type is CV_16U.
Returns
PerformSegmentGpu(InputArray, bool)
Do segmentation on the GPU. This method falls back to the CPU implementation when OpenCV was not built with CUDA support.
public virtual Mat PerformSegmentGpu(InputArray src, bool ifDraw = true)
Parameters
srcInputArraythe input image.
ifDrawboolif true, the returned Mat is a segmented picture where the color of each region is the average color of all pixels in that region, and its data type is the same as the input image. If false, the content of the returned Mat is a matrix of indices describing the region each pixel belongs to, and its data type is CV_16U.