-
Notifications
You must be signed in to change notification settings - Fork 36
CCA is another subspace method like Principal Component Analysis but it seeks a different optimization paradigm. In CCA one has two datasets of random variables X and Y e.g. a set of images and the rotation angle and CCA tries to find maximum correlation between those two.
For the formal definition check out the wikipedia definition of CCA
The implementation of this CCA class follows papers of Melzer T., Reiter M., Bischof H., "Appearance models based on kernel canonical correlation analysis", Pattern Recognition 36, 1961-1971, 2003
The method described here allows to add a regularization term. The value lambda is added in the covariance matrices diagonal entries to avoid singularity problems when inverting the covariance matrices.
The following examples show how to use the CCA class with images and an estimated rotation angle. The example is part of the unit test. It contains three steps:
- Load the images in a matrix x
- Associate an orientation in x and y direction from 0 - 360° to the destination matrix y
- Execute the correlation analysis between x and y.
procedure TTestCCA.TestCCAImages;
var x, y : TDoubleMatrix;
w, h, i : integer;
yp : IMatrix;
start, stop : int64;
begin
// load images
x := LoadImages(w, h, 'CCATest', '*.bmp');
// training orientations
y := TDoubleMatrix.Create(360 div 12, 2);
for i := 0 to y.Width - 1 do
begin
y[i, 0] := sin(i*12*pi/180);
y[i, 1] := cos(i*12*pi/180);
end;
with TMatrixCCA.Create do
try
start := MtxGetTime;
CCA(X, Y);
stop := MtxGetTime;
Status(Format('CCA images took: %.3fms', [(stop - start)/mtxfreq*1000]));
Check(SameValue(R[0, 0], 0.9999, 0.0001), 'Error computation of R failed');
Check(SameValue(R[0, 1], 0.9999, 0.0001), 'Error computation of R failed');
Check((WyT.Height = WyT.Width) and (WyT.Width = 2), 'Dimension error');
// ###########################################
// #### Test projection
for i := 0 to x.Width - 1 do
begin
X.SetSubMatrix(i, 0, 1, X.Height);
Y.SetSubMatrix(i, 0, 1, Y.Height);
yp := Project(X);
Check( CheckMtx( yp.SubMatrix, y.SubMatrix, -1, -1, 1e-1 ), 'Projections not accurate');
end;
finally
Free;
end;
x.Free;
y.Free;
end;