2d-pca (two-dimensional PCA)

Source: Internet
Author: User

 

Traditional one-dimensional PCA and LDA methods are based on image vectors in image recognition. In these face recognition technologies, 2D face image matrices must be first converted to 1D image vectors, then perform PCA or LDA analysis. The disadvantage is obvious:

1. After being converted to one dimension, the dimension is too large and the calculation workload increases.

II. The training of principal component analysis is unsupervised, that is, PCA cannot use the category information of training samples.

3. the recognition rate is not very high.

This article introduces 2 DPCA, which uses two-dimensional information of the image as its name suggests.

2 DPCAAlgorithmIntroduction

If X is set to represent the n-dimensional column vector, image matrix A of mxn is directly projected to X through the following linear changes:

Obtain an M-dimensional column vector Y. X is the projection axis, and Y is called the projection vector of image. The best projection axis X can be determined based on the divergence distribution of y in feature pity. The principles used are as follows:

SX represents the covariance matrix of Y, the projection feature vector of the training sample, and the tr (SX) carries the SX trace. However, when this criterion is the largest value, physical means: Find a projection axis X on which all training samples are projected to maximize the overall scatter matrix (the scatter matrix between sample classes) of the projected feature vectors. The matrix SX can be recorded as a sub-statement as follows:

So,

Visualization of divergence:

Next we will define the following matrix:

GT is defined as the covariance matrix of the image. It is an nxn matrix. We can then directly use the training sample to calculate the GT. Assume that the total number of training samples is m, and the Training image sample is the matrix AJ (j = 1... m), the average image of all training samples is, then the GT can be calculated using the following formula:

The original format can be converted

X is the normalized orthogonal vector. This criterion is called the general spreading criterion in a broad sense. 2 x maximizes the criterion, which is called the optimal projection axis. Physical means: The image matrix has the largest overall dispersion of feature vectors after projection on the axis.

Here, the optimal projection axis xopt is a normalized vector that maximizes J (X.

We usually select a series of standard orthogonal projection axes, that is, if the feature value of the GT is set from large to small, the corresponding vector is:

Image Feature Matrix:

X1,... XD can be used for feature extraction. For a given image sample A, the following formula is used:

 

In this way, we get a set of projection feature vectors Y1,... yd, called the main component vector of image. 2dpca selects a certain number of major component vectors of D to form an mxd matrix, called the feature or feature image of image a, namely:

Use the preceding feature images for classification:

After the image features, each image can obtain a feature matrix. Has C known pattern classification W1, W2 ,..... WC, ni indicates the number of training samples in Class I, the projection feature vector of the training sample image, (I = 1, 2... c; j = 1, 2 ..., ni), the mean of the class I projection feature vector is, within the projection space, the nearest classification rule is: if the sample y meets:

At the same time, the minimum distance classification rule is: If sample y meets

Just compile it:

 

Allsamples = [];  Global  Pathname; Global  Y;  Global  X;  Global  P;  Global  Train_num;  Global  M;  Global  N; m = 112 ; % Rown = 92 ; % Columntrain_num =200  ; Gt = Zeros (n, n); pathname = '  C: \ MATLAB workspace \ mypca \ orl \ s  '  ;  For I = 1 : 40  SUMA = Zeros (m, n );  For J = 1 : 5 A = Imread (strcat (pathname, num2str (I ), '  \ ', Num2str (J ),  ' . PGM '  )); A = Double  (A); Suma = Suma + A; end averagea = Suma/ 5  ;  For J = 1 : 5 A = Imread (strcat (pathname, num2str (I ), '  \ ', Num2str (J ),  ' . PGM '  )); A = Double  (A); gt = Gt + (a-averagea) '  * (A-averagea );  Endend GT = Gt/ Train_num; [v d] = EIG (GT ); For I = 1  : N dd (I) = D (I, I); end [D2 Index] = Sort (DD, '  Descend  '  ); Cols = Size (V, 2  )  For I = 1  : Cols dsort (:, I) = V (:, index (I); End dsum =Sum (dd); dsum_extract = 0  ; P = 0  ;  While (Dsum_extract/dsum < 0.8  ) P = P + 1  ; Dsum_extract = Dsum_extract + Dd (p); end X = Dsort (:, 1  : P); x P size (x) y = Cell ( 40 );  For I = 1 : 40  Tempa = Zeros (m, n );  For J = 1 : 5  A = Imread (strcat (pathname, num2str (I ), '  \ ', Num2str (J ),  ' . PGM '  )); A = Double  (A); Tempa = Tempa + A; end Tempa = Tempa/ 5  ; Y (I) = Mat2cell (Tempa * X); End % Test course ACCU = 0  ;  For I = 1 : 40       For J = 6 : 10  A = Imread (strcat (pathname, num2str (I ), '  \ ', Num2str (J ),  ' . PGM '  )); A = Double  (A); Tempy = * X; tempindex = 1  ; Tempsum = 10000000  ; For K = 1 : 40  Sumlast = 0.0  ; YY = Cell2mat (Y (k ));  For L = 1  : P sumlast = Sumlast + norm (Tempy (:, L )- YY (:, L); End  If (Tempsum> Sumlast) tempsum =Sumlast; tempindex = K; end  If Tempindex = I ACCU = ACCU + 1  ; End Accuracy = ACCU/ 200                                          

Result:

The cross-validation method is not used, so the accuracy is not very high (I am lazy :)). It is only for reference. If there is an error, I hope to help me point it out.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.