Table of Contents

Class PCTSignatures

Namespace
OpenCvSharp.XFeatures2D
Assembly
OpenCvSharp.dll

Class implementing PCT (position-color-texture) signature extraction, as described in KrulisLS16. The algorithm is divided into a feature sampler and a clusterizer. The feature sampler produces samples at a given set of coordinates, and the clusterizer produces clusters of these samples using the k-means algorithm; the resulting set of clusters is the signature of the input image.

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

Properties

ClusterMinSize

This parameter, multiplied by the index of iteration, gives the lower limit for cluster size. Clusters containing fewer points than specified by the limit have their centroid dismissed and points are reassigned.

public int ClusterMinSize { get; set; }

Property Value

int

DistanceFunction

Distance function selector used for measuring distance between two points in k-means.

public PCTSignaturesDistanceFunction DistanceFunction { get; set; }

Property Value

PCTSignaturesDistanceFunction

DropThreshold

Remove centroids in k-means whose weight is lesser or equal to the given threshold.

public float DropThreshold { get; set; }

Property Value

float

GrayscaleBits

Color resolution of the greyscale bitmap represented in allocated bits (i.e., value 4 means that 16 shades of grey are used). The greyscale bitmap is used for computing contrast and entropy values.

public int GrayscaleBits { get; set; }

Property Value

int

InitSeedCount

Number of initial seeds (initial number of clusters) for the k-means algorithm.

public int InitSeedCount { get; }

Property Value

int

IterationCount

Number of iterations of the k-means clustering. We use a fixed number of iterations, since the modified clustering is pruning clusters (not iteratively refining k clusters).

public int IterationCount { get; set; }

Property Value

int

JoiningDistance

Threshold euclidean distance between two centroids. If two cluster centers are closer than this distance, one of the centroids is dismissed and points are reassigned.

public float JoiningDistance { get; set; }

Property Value

float

MaxClustersCount

Maximal number of generated clusters. If the number is exceeded, the clusters are sorted by their weights and the smallest clusters are cropped.

public int MaxClustersCount { get; set; }

Property Value

int

SampleCount

Number of initial samples taken from the image.

public int SampleCount { get; }

Property Value

int

Remarks

OpenCV's native implementation of this getter is a known copy-paste bug: it returns the same value as GrayscaleBits instead of the actual sample count passed to Create().

WeightA

Weight (multiplicative constant) that linearly stretches the a (CIE Lab) axis of the feature space.

public float WeightA { get; set; }

Property Value

float

WeightB

Weight (multiplicative constant) that linearly stretches the b (CIE Lab) axis of the feature space.

public float WeightB { get; set; }

Property Value

float

WeightContrast

Weight (multiplicative constant) that linearly stretches the contrast axis of the feature space.

public float WeightContrast { get; set; }

Property Value

float

WeightEntropy

Weight (multiplicative constant) that linearly stretches the entropy axis of the feature space.

public float WeightEntropy { get; set; }

Property Value

float

WeightL

Weight (multiplicative constant) that linearly stretches the L (lightness) axis of the feature space.

public float WeightL { get; set; }

Property Value

float

WeightX

Weight (multiplicative constant) that linearly stretches the x-axis of the feature space.

public float WeightX { get; set; }

Property Value

float

WeightY

Weight (multiplicative constant) that linearly stretches the y-axis of the feature space.

public float WeightY { get; set; }

Property Value

float

WindowRadius

Size of the texture sampling window used to compute contrast and entropy (center of the window is always in the pixel selected by x,y coordinates of the corresponding feature sample).

public int WindowRadius { get; set; }

Property Value

int

Methods

ComputeSignature(InputArray, OutputArray)

Computes signature of a given image.

public void ComputeSignature(InputArray image, OutputArray signature)

Parameters

image InputArray

Input image of CV_8U type.

signature OutputArray

Output computed signature.

ComputeSignatures(IEnumerable<Mat>)

Computes signatures for multiple images in parallel.

public Mat[] ComputeSignatures(IEnumerable<Mat> images)

Parameters

images IEnumerable<Mat>

Vector of input images of CV_8U type.

Returns

Mat[]

Vector of computed signatures.

Create(IEnumerable<Point2f>, IEnumerable<int>)

Creates PCTSignatures algorithm using pre-generated sampling points and clusterization seed indexes.

public static PCTSignatures Create(IEnumerable<Point2f> initSamplingPoints, IEnumerable<int> initClusterSeedIndexes)

Parameters

initSamplingPoints IEnumerable<Point2f>

Sampling points used in image sampling.

initClusterSeedIndexes IEnumerable<int>

Indexes of initial clusterization seeds. Its size must be lower or equal to initSamplingPoints.Length.

Returns

PCTSignatures

Create(IEnumerable<Point2f>, int)

Creates PCTSignatures algorithm using pre-generated sampling points and number of clusterization seeds. It uses the provided sampling points and generates its own clusterization seed indexes.

public static PCTSignatures Create(IEnumerable<Point2f> initSamplingPoints, int initSeedCount)

Parameters

initSamplingPoints IEnumerable<Point2f>

Sampling points used in image sampling.

initSeedCount int

Number of initial clusterization seeds. Must be lower or equal to initSamplingPoints.Length.

Returns

PCTSignatures

Create(int, int, PCTSignaturesPointDistribution)

Creates PCTSignatures algorithm using sample and seed count. It generates its own sets of sampling points and clusterization seed indexes.

public static PCTSignatures Create(int initSampleCount = 2000, int initSeedCount = 400, PCTSignaturesPointDistribution pointDistribution = PCTSignaturesPointDistribution.Uniform)

Parameters

initSampleCount int

Number of points used for image sampling.

initSeedCount int

Number of initial clusterization seeds. Must be lower or equal to initSampleCount.

pointDistribution PCTSignaturesPointDistribution

Distribution of generated points.

Returns

PCTSignatures

DrawSignature(InputArray, InputArray, OutputArray, float, int)

Draws signature in the source image and outputs the result. Signatures are visualized as a circle with radius based on signature weight and color based on signature color. Contrast and entropy are not visualized.

public static void DrawSignature(InputArray source, InputArray signature, OutputArray result, float radiusToShorterSideRatio = 0.125, int borderThickness = 1)

Parameters

source InputArray

Source image.

signature InputArray

Image signature.

result OutputArray

Output result.

radiusToShorterSideRatio float

Determines maximal radius of signature in the output image.

borderThickness int

Border thickness of the visualized signature.

GenerateInitPoints(int, PCTSignaturesPointDistribution)

Generates initial sampling points according to the selected point distribution.

public static Point2f[] GenerateInitPoints(int count, PCTSignaturesPointDistribution pointDistribution)

Parameters

count int

Number of points to generate.

pointDistribution PCTSignaturesPointDistribution

Point distribution selector.

Returns

Point2f[]

The generated points, with coordinates in range [0..1).

GetInitSeedIndexes()

Initial seeds (initial number of clusters) for the k-means algorithm.

public int[] GetInitSeedIndexes()

Returns

int[]

GetSamplingPoints()

Initial samples taken from the image. These sampled features become the input for clustering.

public Point2f[] GetSamplingPoints()

Returns

Point2f[]

SetInitSeedIndexes(IEnumerable<int>)

Initial seed indexes for the k-means algorithm.

public void SetInitSeedIndexes(IEnumerable<int> initSeedIndexes)

Parameters

initSeedIndexes IEnumerable<int>

SetSamplingPoints(IEnumerable<Point2f>)

Sets sampling points used to sample the input image.

public void SetSamplingPoints(IEnumerable<Point2f> samplingPoints)

Parameters

samplingPoints IEnumerable<Point2f>

Vector of sampling points in range [0..1). Their count must be greater or equal to the clusterization seed count.

SetTranslation(int, float)

Translations of the individual axes of the feature space.

public void SetTranslation(int idx, float value)

Parameters

idx int

ID of the translation (0=weight, 1=x, 2=y, 3=L, 4=a, 5=b, 6=contrast, 7=entropy).

value float

Value of the translation.

SetTranslations(IEnumerable<float>)

Translations of the individual axes of the feature space.

public void SetTranslations(IEnumerable<float> translations)

Parameters

translations IEnumerable<float>

Values of all translations (0=weight, 1=x, 2=y, 3=L, 4=a, 5=b, 6=contrast, 7=entropy).

SetWeight(int, float)

Weights (multiplicative constants) that linearly stretch individual axes of the feature space.

public void SetWeight(int idx, float value)

Parameters

idx int

ID of the weight (0=weight, 1=x, 2=y, 3=L, 4=a, 5=b, 6=contrast, 7=entropy).

value float

Value of the weight.

SetWeights(IEnumerable<float>)

Weights (multiplicative constants) that linearly stretch individual axes of the feature space.

public void SetWeights(IEnumerable<float> weights)

Parameters

weights IEnumerable<float>

Values of all weights (0=weight, 1=x, 2=y, 3=L, 4=a, 5=b, 6=contrast, 7=entropy).