Class ScanSegment
Class implementing the F-DBSCAN (Accelerated superpixel image segmentation with a parallelized DBSCAN algorithm) superpixels algorithm by Loke SC, et al.
public class ScanSegment : SharedPtrObject, IDisposable, IAlgorithm
- Inheritance
-
ScanSegment
- Implements
- Inherited Members
- Extension Methods
Remarks
The algorithm uses a parallelised DBSCAN cluster search that is resistant to noise, competitive in segmentation quality, and faster than existing superpixel segmentation methods. When tested on the Berkeley Segmentation Dataset, the average processing speed is 175 frames/s with a Boundary Recall of 0.797 and an Achievable Segmentation Accuracy of 0.944. The computational complexity is quadratic O(n2) and more suited to smaller images, but can still process a 2MP colour image faster than the SEEDS algorithm in OpenCV. The output is deterministic when the number of processing threads is fixed, and requires the source image to be in Lab colour format.
Constructors
ScanSegment(int, int, int, int, bool)
Initializes a ScanSegment object.
public ScanSegment(int imageWidth, int imageHeight, int numSuperpixels, int slices = 8, bool mergeSmall = true)
Parameters
imageWidth
intImage width.
imageHeight
intImage height.
numSuperpixels
intDesired number of superpixels. Note that the actual number may be smaller due to restrictions (depending on the image size). Use NumberOfSuperpixels to get the actual number.
slices
intNumber of processing threads for parallelisation. Setting -1 uses the maximum number of threads. In practice, four threads is enough for smaller images and eight threads for larger ones.
mergeSmall
boolMerge small segments to give the desired number of superpixels. Processing is much faster without merging, but many small segments will be left in the image.
Properties
AlgorithmPtr
Pointer to cv::Algorithm
public nint AlgorithmPtr { get; }
Property Value
NumberOfSuperpixels
Returns the actual superpixel segmentation from the last image processed using iterate. Returns zero if no image has been processed.
public int NumberOfSuperpixels { get; }
Property Value
Methods
DisposeObject()
protected override void DisposeObject()
GetLabelContourMask(IOutputArray, bool)
Returns the mask of the superpixel segmentation stored in the ScanSegment object.
public void GetLabelContourMask(IOutputArray image, bool thickLine = false)
Parameters
image
IOutputArrayCV_8UC1 image mask where 255 indicates that the pixel is a superpixel border, and 0 otherwise.
thickLine
boolIf false, the border is only one pixel wide, otherwise all pixels at the border are masked.
GetLabels(IOutputArray)
Returns the segmentation labeling of the image. Each label represents a superpixel, and each pixel is assigned to one superpixel label.
public void GetLabels(IOutputArray labelsOut)
Parameters
labelsOut
IOutputArrayA CV_32UC1 integer array containing the labels of the superpixel segmentation. The labels are in the range [0, NumberOfSuperpixels].
Iterate(IInputArray)
Calculates the superpixel segmentation on a given image with the initialized parameters in the ScanSegment object. This function can be called again for other images without the need of initializing the algorithm with createScanSegment(). This save the computational cost of allocating memory for all the structures of the algorithm.
public void Iterate(IInputArray img)
Parameters
img
IInputArrayInput image. Supported format: CV_8UC3. Image size must match with the initialized image size with the function createScanSegment(). It MUST be in Lab color space.