Table of Contents

Class ScanSegment

Namespace
OpenCvSharp.XImgProc
Assembly
OpenCvSharp.dll

Class implementing the F-DBSCAN (Accelerated superpixel image segmentation with a parallelized DBSCAN algorithm) superpixels algorithm.

The algorithm uses a parallelised DBSCAN cluster search that is resistant to noise, competitive in segmentation quality, and faster than existing superpixel segmentation methods. The output is deterministic when the number of processing threads is fixed, and requires the source image to be in Lab colour format.

public class ScanSegment : Algorithm, IDisposable
Inheritance
ScanSegment
Implements
Inherited Members

Methods

Create(int, int, int, int, bool)

Initializes a ScanSegment object.

The function initializes a ScanSegment object for the input image. It stores the parameters of the image: image_width and image_height. It also sets the parameters of the F-DBSCAN superpixel algorithm, which are: num_superpixels, threads, and merge_small.

public static ScanSegment Create(int imageWidth, int imageHeight, int numSuperpixels, int slices = 8, bool mergeSmall = true)

Parameters

imageWidth int

Image width.

imageHeight int

Image height.

numSuperpixels int

Desired number of superpixels. Note that the actual number may be smaller due to restrictions (depending on the image size). Use GetNumberOfSuperpixels() to get the actual number.

slices int

Number 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 bool

Merge 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.

Returns

ScanSegment

GetLabelContourMask(OutputArray, bool)

Returns the mask of the superpixel segmentation stored in the ScanSegment object. The function returns the boundaries of the superpixel segmentation.

public virtual void GetLabelContourMask(OutputArray image, bool thickLine = false)

Parameters

image OutputArray

Return: CV_8UC1 image mask where -1 indicates that the pixel is a superpixel border, and 0 otherwise.

thickLine bool

If false, the border is only one pixel wide, otherwise all pixels at the border are masked.

GetLabels(OutputArray)

Returns the segmentation labeling of the image. Each label represents a superpixel, and each pixel is assigned to one superpixel label.

public virtual void GetLabels(OutputArray labelsOut)

Parameters

labelsOut OutputArray

Return: A CV_32UC1 integer array containing the labels of the superpixel segmentation. The labels are in the range [0, GetNumberOfSuperpixels()].

GetNumberOfSuperpixels()

Returns the actual superpixel segmentation from the last image processed using Iterate. Returns zero if no image has been processed.

public virtual int GetNumberOfSuperpixels()

Returns

int

Iterate(InputArray)

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 Create(). This saves the computational cost of allocating memory for all the structures of the algorithm.

public virtual void Iterate(InputArray img)

Parameters

img InputArray

Input image. Supported format: CV_8UC3. Image size must match with the initialized image size with the function Create(). It MUST be in Lab color space.