Take the 2-minute tour ×

I have found a problem when I use the method getCols() of type Matrix. Check this piece of code:

let suppose that size of orig is [1000, 384] and numFeat is = 50;

private Matrix<float> ComputePCA(Matrix<float> orig, int numFeat)
        Matrix<float> avg = new Matrix<float>(1, orig.Cols);
        Matrix<float> eigval = new Matrix<float>(orig.Cols, 1);
        Matrix<float> eigvec = new Matrix<float>(orig.Cols, orig.Cols);
        Matrix<float> featMat = new Matrix<float>(orig.Rows, numFeat);

        CvInvoke.cvCalcPCA(masterMat, avg, eigval, eigvec, Emgu.CV.CvEnum.PCA_TYPE.CV_PCA_DATA_AS_ROW);

        Matrix<float> choosenAutovec = new Matrix<float>(orig.Cols, numFeat);

        choosenAutovec = eigvec.GetCols(0, numFeat - 1);

        featMat = choosenAutovec.Transpose() * orig.Transpose();

        return featMat.Transpose();

after eigvec.GetCols I suppose to have a variable choosenAutovec of size [384, 50] right? But I get a matrix [384, 384] instead... Any suggestions to take just the first 50 cols?


share|improve this question
add comment

1 Answer

Taking the first 50 columns is done almost correctly except numFeat must not be decremented since the index in the second parameter of GetCols is exclusive.

As for matrix size, after calling GetCols the Data property of choosenAutovec references the same array of floats as the similar property of eigvec. However, the indexers of choosenAutovec will work as if it was a 384 by 50 matrix. You can check it yourself by setting a breakpoint after the featMat assignment. featMat size will be 50 by 1000 as intended.

At the following page the behavior of GetCol (which is similar to GetCols) is described in detail in the comment by Canming: http://www.emgu.com/bugs/show_bug.cgi?id=19

share|improve this answer
add comment

Your Answer


