Show / Hide Table of Contents

Class PCA

Principal Component Analysis

Inheritance
System.Object
DisposableObject
DisposableCvObject
PCA
Implements
ICvPtrHolder
Inherited Members
DisposableCvObject.ptr
DisposableCvObject.CvPtr
DisposableObject.DataHandle
DisposableObject.IsDisposed
DisposableObject.IsEnabledDispose
DisposableObject.AllocatedMemory
DisposableObject.AllocatedMemorySize
DisposableObject.Dispose()
DisposableObject.Dispose(Boolean)
DisposableObject.DisposeManaged()
DisposableObject.AllocGCHandle(Object)
DisposableObject.AllocMemory(Int32)
DisposableObject.NotifyMemoryPressure(Int64)
DisposableObject.ThrowIfDisposed()
Namespace: OpenCvSharp
Assembly: OpenCvSharp.dll
Syntax
public class PCA : DisposableCvObject, ICvPtrHolder

Constructors

| Improve this Doc View Source

PCA()

default constructor.

The default constructor initializes an empty PCA structure. The other constructors initialize the structure and call PCA::operator()().

Declaration
public PCA()
| Improve this Doc View Source

PCA(InputArray, InputArray, PCA.Flags, Double)

Constructor

Declaration
public PCA(InputArray data, InputArray mean, PCA.Flags flags, double retainedVariance)
Parameters
Type Name Description
InputArray data

input samples stored as matrix rows or matrix columns.

InputArray mean

optional mean value; if the matrix is empty (noArray()), the mean is computed from the data.

PCA.Flags flags

operation flags; currently the parameter is only used to specify the data layout (PCA::Flags)

System.Double retainedVariance

Percentage of variance that PCA should retain. Using this parameter will let the PCA decided how many components to retain but it will always keep at least 2.

| Improve this Doc View Source

PCA(InputArray, InputArray, PCA.Flags, Int32)

Constructor

Declaration
public PCA(InputArray data, InputArray mean, PCA.Flags flags, int maxComponents = 0)
Parameters
Type Name Description
InputArray data

input samples stored as matrix rows or matrix columns.

InputArray mean

optional mean value; if the matrix is empty (@c noArray()), the mean is computed from the data.

PCA.Flags flags

operation flags; currently the parameter is only used to specify the data layout (PCA::Flags)

System.Int32 maxComponents

maximum number of components that PCA should retain; by default, all the components are retained.

Properties

| Improve this Doc View Source

Eigenvalues

eigenvalues of the covariation matrix

Declaration
public Mat Eigenvalues { get; }
Property Value
Type Description
Mat
| Improve this Doc View Source

Eigenvectors

eigenvalues of the covariation matrix

Declaration
public Mat Eigenvectors { get; }
Property Value
Type Description
Mat
| Improve this Doc View Source

Mean

mean value subtracted before the projection and added after the back projection

Declaration
public Mat Mean { get; }
Property Value
Type Description
Mat

Methods

| Improve this Doc View Source

BackProject(InputArray)

Reconstructs vectors from their PC projections.

The methods are inverse operations to PCA::project. They take PC coordinates of projected vectors and reconstruct the original vectors. Unless all the principal components have been retained, the reconstructed vectors are different from the originals. But typically, the difference is small if the number of components is large enough (but still much smaller than the original vector dimensionality). As a result, PCA is used.

Declaration
public Mat BackProject(InputArray vec)
Parameters
Type Name Description
InputArray vec

coordinates of the vectors in the principal component subspace, the layout and size are the same as of PCA::project output vectors.

Returns
Type Description
Mat
| Improve this Doc View Source

BackProject(InputArray, OutputArray)

Reconstructs vectors from their PC projections.

The methods are inverse operations to PCA::project. They take PC coordinates of projected vectors and reconstruct the original vectors. Unless all the principal components have been retained, the reconstructed vectors are different from the originals. But typically, the difference is small if the number of components is large enough (but still much smaller than the original vector dimensionality). As a result, PCA is used.

Declaration
public void BackProject(InputArray vec, OutputArray result)
Parameters
Type Name Description
InputArray vec

coordinates of the vectors in the principal component subspace, the layout and size are the same as of PCA::project output vectors.

OutputArray result

reconstructed vectors; the layout and size are the same as of PCA::project input vectors.

| Improve this Doc View Source

Compute(InputArray, InputArray, PCA.Flags, Int32)

Performs PCA.

The operator performs %PCA of the supplied dataset. It is safe to reuse the same PCA structure for multiple datasets. That is, if the structure has been previously used with another dataset, the existing internal data is reclaimed and the new @ref eigenvalues, @ref eigenvectors and @ref mean are allocated and computed.

The computed @ref eigenvalues are sorted from the largest to the smallest and the corresponding @ref eigenvectors are stored as eigenvectors rows.

Declaration
public PCA Compute(InputArray data, InputArray mean, PCA.Flags flags, int maxComponents = 0)
Parameters
Type Name Description
InputArray data

input samples stored as the matrix rows or as the matrix columns.

InputArray mean

optional mean value; if the matrix is empty (noArray()), the mean is computed from the data.

PCA.Flags flags

operation flags; currently the parameter is only used to specify the data layout. (Flags)

System.Int32 maxComponents

maximum number of components that PCA should retain; by default, all the components are retained.

Returns
Type Description
PCA
| Improve this Doc View Source

ComputeVar(InputArray, InputArray, PCA.Flags, Double)

Performs PCA.

The operator performs %PCA of the supplied dataset. It is safe to reuse the same PCA structure for multiple datasets. That is, if the structure has been previously used with another dataset, the existing internal data is reclaimed and the new @ref eigenvalues, @ref eigenvectors and @ref mean are allocated and computed.

The computed @ref eigenvalues are sorted from the largest to the smallest and the corresponding @ref eigenvectors are stored as eigenvectors rows.

Declaration
public PCA ComputeVar(InputArray data, InputArray mean, PCA.Flags flags, double retainedVariance)
Parameters
Type Name Description
InputArray data

input samples stored as the matrix rows or as the matrix columns.

InputArray mean

optional mean value; if the matrix is empty (noArray()), the mean is computed from the data.

PCA.Flags flags

operation flags; currently the parameter is only used to specify the data layout. (PCA::Flags)

System.Double retainedVariance

Percentage of variance that %PCA should retain. Using this parameter will let the %PCA decided how many components to retain but it will always keep at least 2.

Returns
Type Description
PCA
| Improve this Doc View Source

DisposeUnmanaged()

Releases unmanaged resources

Declaration
protected override void DisposeUnmanaged()
Overrides
DisposableCvObject.DisposeUnmanaged()
| Improve this Doc View Source

Project(InputArray)

Projects vector(s) to the principal component subspace.

The methods project one or more vectors to the principal component subspace, where each vector projection is represented by coefficients in the principal component basis. The first form of the method returns the matrix that the second form writes to the result. So the first form can be used as a part of expression while the second form can be more efficient in a processing loop.

Declaration
public Mat Project(InputArray vec)
Parameters
Type Name Description
InputArray vec

input vector(s); must have the same dimensionality and the same layout as the input data used at %PCA phase, that is, if DATA_AS_ROW are specified, then vec.cols==data.cols (vector dimensionality) and vec.rows is the number of vectors to project, and the same is true for the PCA::DATA_AS_COL case.

Returns
Type Description
Mat
| Improve this Doc View Source

Project(InputArray, OutputArray)

Projects vector(s) to the principal component subspace.

Declaration
public void Project(InputArray vec, OutputArray result)
Parameters
Type Name Description
InputArray vec

input vector(s); must have the same dimensionality and the same layout as the input data used at PCA phase, that is, if DATA_AS_ROW are specified, then vec.cols==data.cols (vector dimensionality) and vec.rows is the number of vectors to project, and the same is true for the PCA::DATA_AS_COL case.

OutputArray result

output vectors; in case of PCA::DATA_AS_COL, the output matrix has as many columns as the number of input vectors, this means that result.cols==vec.cols and the number of rows match the number of principal components (for example, maxComponents parameter passed to the constructor).

| Improve this Doc View Source

Read(FileNode)

Load PCA objects. Loads @ref eigenvalues @ref eigenvectors and @ref mean from specified FileNode

Declaration
public void Read(FileNode fn)
Parameters
Type Name Description
FileNode fn
| Improve this Doc View Source

Write(FileStorage)

Write PCA objects. Writes @ref eigenvalues @ref eigenvectors and @ref mean to specified FileStorage

Declaration
public void Write(FileStorage fs)
Parameters
Type Name Description
FileStorage fs

Implements

ICvPtrHolder
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX