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
DistanceFunction
Distance function selector used for measuring distance between two points in k-means.
public PCTSignaturesDistanceFunction DistanceFunction { get; set; }
Property Value
DropThreshold
Remove centroids in k-means whose weight is lesser or equal to the given threshold.
public float DropThreshold { get; set; }
Property Value
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
InitSeedCount
Number of initial seeds (initial number of clusters) for the k-means algorithm.
public int InitSeedCount { get; }
Property Value
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
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
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
SampleCount
Number of initial samples taken from the image.
public int SampleCount { get; }
Property Value
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
WeightB
Weight (multiplicative constant) that linearly stretches the b (CIE Lab) axis of the feature space.
public float WeightB { get; set; }
Property Value
WeightContrast
Weight (multiplicative constant) that linearly stretches the contrast axis of the feature space.
public float WeightContrast { get; set; }
Property Value
WeightEntropy
Weight (multiplicative constant) that linearly stretches the entropy axis of the feature space.
public float WeightEntropy { get; set; }
Property Value
WeightL
Weight (multiplicative constant) that linearly stretches the L (lightness) axis of the feature space.
public float WeightL { get; set; }
Property Value
WeightX
Weight (multiplicative constant) that linearly stretches the x-axis of the feature space.
public float WeightX { get; set; }
Property Value
WeightY
Weight (multiplicative constant) that linearly stretches the y-axis of the feature space.
public float WeightY { get; set; }
Property Value
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
Methods
ComputeSignature(InputArray, OutputArray)
Computes signature of a given image.
public void ComputeSignature(InputArray image, OutputArray signature)
Parameters
imageInputArrayInput image of CV_8U type.
signatureOutputArrayOutput computed signature.
ComputeSignatures(IEnumerable<Mat>)
Computes signatures for multiple images in parallel.
public Mat[] ComputeSignatures(IEnumerable<Mat> images)
Parameters
imagesIEnumerable<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
initSamplingPointsIEnumerable<Point2f>Sampling points used in image sampling.
initClusterSeedIndexesIEnumerable<int>Indexes of initial clusterization seeds. Its size must be lower or equal to initSamplingPoints.Length.
Returns
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
initSamplingPointsIEnumerable<Point2f>Sampling points used in image sampling.
initSeedCountintNumber of initial clusterization seeds. Must be lower or equal to initSamplingPoints.Length.
Returns
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
initSampleCountintNumber of points used for image sampling.
initSeedCountintNumber of initial clusterization seeds. Must be lower or equal to initSampleCount.
pointDistributionPCTSignaturesPointDistributionDistribution of generated points.
Returns
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
sourceInputArraySource image.
signatureInputArrayImage signature.
resultOutputArrayOutput result.
radiusToShorterSideRatiofloatDetermines maximal radius of signature in the output image.
borderThicknessintBorder 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
countintNumber of points to generate.
pointDistributionPCTSignaturesPointDistributionPoint 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
initSeedIndexesIEnumerable<int>
SetSamplingPoints(IEnumerable<Point2f>)
Sets sampling points used to sample the input image.
public void SetSamplingPoints(IEnumerable<Point2f> samplingPoints)
Parameters
samplingPointsIEnumerable<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
idxintID of the translation (0=weight, 1=x, 2=y, 3=L, 4=a, 5=b, 6=contrast, 7=entropy).
valuefloatValue of the translation.
SetTranslations(IEnumerable<float>)
Translations of the individual axes of the feature space.
public void SetTranslations(IEnumerable<float> translations)
Parameters
translationsIEnumerable<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
idxintID of the weight (0=weight, 1=x, 2=y, 3=L, 4=a, 5=b, 6=contrast, 7=entropy).
valuefloatValue 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
weightsIEnumerable<float>Values of all weights (0=weight, 1=x, 2=y, 3=L, 4=a, 5=b, 6=contrast, 7=entropy).