
function Eigenvector = TLDA_single(A,options,Dim)
% A       image matrix, the size is m*n*N
%         N denotes the number of images and equals the number of classes
%         m and n denote the row and column of image, respectively.
% options - Struct value in Matlab. The fields in options
%           that can be set:
%           k ----determins how to construct the Con_A using the corresponding
%           image,the default value is 3;
%           Dim --- The dimensionality of the reduced subspace. 


[m,n,N] = size(A);
Con_A=construct_image(A,options);
global_mean = mean(Con_A,3);
Gw = zeros(n,n);
Gb = zeros(n,n);
for i = 1 : N
    index_L = (i-1)*2+1;
    index_R = 2*i;
    b = Con_A(:,:,index_R) - Con_A(:,:,index_L);
    class_mean = mean(Con_A(:,:,index_L:index_R),3);
    Gw = Gw + b'*b;
    Gb = Gb + (class_mean - global_mean)'*(class_mean - global_mean);
end
[Eigenvector, Eigenvalue] = eigs(inv(Gw)*Gb,Dim);


