2
votes

Input : LBP Feature extracted from an image with dimension 75520, so the input LBP data contains 1 row and 75520 columns.

Required Output: Apply PCA on input to reduce the dimension,

Currently my code look like,

void PCA_DimensionReduction(Mat &src, Mat &dst){

    int PCA_DIMENSON_VAL 40
    Mat tmp = src.reshape(1,1); //1 rows X 75520 cols
    Mat projection_result;
    Mat input_feature_vector;
    Mat norm_tmp;
    normalize(tmp,input_feature_vector,0,1,NORM_MINMAX,CV_32FC1);
    PCA pca(input_feature_vector,Mat(),CV_PCA_DATA_AS_ROW, PCA_DIMENSON_VAL);
    pca.project(input_feature_vector,projection_result);
    dst = projection_result.reshape(1,1);
}

Basically I am using this features to match similarity between two images, but I am not getting proper result as without applying PCA.

Any help will be appreciated...

Regards

Haris...

1
hi-dim lbp, cool ;) but shouldn't you train one big pca (offline) for all images ? not one per image ? - berak
hi, @Haris, actually, i'm playing with the same idea, atm. went all the way from pca to random-projections, then to walsh-hadamard, not forgetting wavelets, finally towards a simple dft -> throw_out_hf -> dft_back, but in the end - not using lbp(u) but a much shorter four-patch-lbp feature(16 bins only, instead of 256[or even 59 for lbpu], and then skipping any feature compression) worked better for me. comments ? ;) - berak
i'd be also curious, how you solved the : 'IntraFace not available' problem ;) (my main problem atm is to find a good replacement for that ...) - berak
Hi @berak thanks for reply,regarding your first comment, I am following the implementation here, but no idea how to use PCA to reduce dimension. Currently I am getting feature vector of size 75520, but confused with how to make it input for PCA. - Haris
Hi, I have some query about your second comment, in your four-patch-lbp feature extraction, how do you patch face?, are you considering the entire face?, or based on some land-mark? - Haris

1 Answers

3
votes

you will have to collect feature vectors from a lot of images, make a single pca from that (offline), and later use the mean & eigenvectors for the projection.

// let's say, you have collected 10 feature vectors a 30 elements.
// flatten them to a single row (reshape(1,1)) and push_back into a big Data Mat

Mat D(10,30,CV_32F); // 10 rows(features) a 30 elements
randu(D,0,10);       // only for the simulation here
cerr << D.size() << endl;
// [30 x 10]


// now make a pca, that will only retain 6 eigenvectors
// so the later projections are shortened to 6 elements:

PCA p(D,Mat(),CV_PCA_DATA_AS_ROW,6);
cerr << p.eigenvectors.size() << endl;
// [30 x 6]

// now, that the training step is done, we can use it to
// shorten feature vectors:
// either keep the PCA around for projecting:

// a random test vector, 
Mat v(1,30,CV_32F);
randu(v,0,30);

// pca projection:
Mat vp = p.project(v);

cerr << vp.size() << endl;
cerr << vp << endl;
// [6 x 1]
// [-4.7032223, 0.67155731, 15.192059, -8.1542597, -4.5874329, -3.7452228]


// or, maybe, save the pca.mean and pca.eigenvectors only, and do your own projection:

Mat vp2 = (v - mean) * eigenvectors.t();

cerr << vp2.size() << endl;
cerr << vp2 << endl;
//[6 x 1]
//[-4.7032223, 0.67155731, 15.192059, -8.1542597, -4.5874329, -3.7452228]

well, oh, here's the downside: calculating a pca from 4.4k train images a 75k feature elements will take like a good day ;)