DOCX

GABOR

By Robin Stevens,2014-04-11 21:55
13 views 0
GABOR

    for j=1:1:TestClass

     for i=1:1:TestNum

    ;1Recognition str_temp=int2str(j);

     str = int2str(i);

     str = strcat('D:\LDD\Train\',str_temp,'\',str,'.pgm'); %function img=imread(str); Aver_Percen=Recognition(TrainNum,TestNu imshow(img); m,TrainClass,TestClass) %TrainNum=10; GaborData(:,:,i)=Gabor(img,TrainNum,Sca,Or%TrainClass=1; i,irow,icol); %TrainClass=3; GaborData_Vector(:,i,j)= TrainNum=5; reshape(GaborData(:,:,i),irow_Gabor*Sca*OriTestNum=5; /4,1); TrainClass=40; end TestClass=40; end [chara,Eigenfaces]=PCA(GaborData_Vector,TSca=4; rainNum,TrainClass); Ori=8; %Ori_DownSample=4; %计算每一类图像的均值 img=imread('D:\LDD\Train\1\1.pgm'); aver=zeros(irow_Gabor*Sca*Ori/4,TrainClass[irow icol] = size(img); ); img_size=irow*icol; for j=1:1:TrainClass %flag=0; %GaborData=zeros(img_size,Sca*Ori,TrainNaver(:,j)=mean(GaborData_Vector(:,:,j),2); um); end % for i=1:1:size(TrainFiles,1) % Train_Number=Train_Number+1; %计算总体的类均值 % end aver_matrix=[]; % Train_Number=Train_Number-2; for j=1:1:TrainClass %GaborData=zeros(10304,40,Train_Number); aver_matrix=[aver_matrix aver(:,j)]; %str = int2str(t); end %img=imread('D:\训练样本aver_whole=mean(aver_matrix,2); 1\',str,'\1.pgm'); temp=Gabor(img,TrainNum,Sca,Ori,irow,icol)Gabor_PCA=zeros(chara,TrainNum,TrainClas; s); %temp=Gabor(img,TrainNum,Sca, Ori,irow,icol); %提取每幅图片的PCA特征 [irow_Gabor,icol_Gabor]=size(temp); for i=1:1:TrainClass for j=1:1:TrainNum GaborData=zeros(irow_Gabor,Sca*Ori/4,Trai nNum); differ=GaborData_Vector(:,j,i)-aver_whole; GaborData_Vector=zeros(irow_Gabor*Sca*O temp=Eigenfaces'*differ; ri/4,TrainNum,TrainClass); Gabor_PCA(:,j,i)=temp; %提取图像的gabor特征

     1 / 5

     end min=Euc_Distance(j,1); end class_Euc(i,c)=j;

     end

    %计算每幅图片的FDA特征 end

    [T,aver_Fisher,Train_Fisher]=FDA(Gabor_PC end

    A,TrainNum,TrainClass,chara); end

class_Euc=ones(TrainNum,TrainClass); %计算识别率

    %比较;欧式距离; num=0;

    for c=1:1:TestClass Percen_Num=zeros(TrainClass,1);

     for i=1:1:TestNum for i=1:1:TestClass

     str_temp=int2str(c); Percen_Vector=class_Euc(:,i);

     str = int2str(i); for j=1:1:TestNum

     str = if Percen_Vector(j,1)==i strcat('D:\LDD\Test\',str_temp,'\',str,'.pgm'); num=num+1;

     InputImage = imread(str); end

     end

    Test_Gabor=Gabor(InputImage,TrainNum,Sca Percen_Num(i,1)=num/TestNum; ,Ori,irow,icol); num=0;

     end

    Test_Gabor_Vector=reshape(Test_Gabor,irowPercen_Sum=0;

    _Gabor*Sca*Ori/4,1); for i=1:1:TestClass

     Difference =

    double(Test_Gabor_Vector)-aver_whole; Percen_Sum=Percen_Sum+Percen_Num(i,1);

     ProjectedTestImage = end

    Eigenfaces'*Difference; % 降维 Aver_Percen=Percen_Sum/TestClass;

     fname='D:\LDD\Test_Gabor_PCA_FDA_MaGabor_Fisher=T'*ProjectedTestImage;% gnitude_LG1\'

    Fisher特征 save(fname,'Aver_Percen','class_Euc');

     %PCA(TrainData,TrainNum,TrainClass)

     %计算欧式距离

     Euc_Distance=zeros(TrainClass,1);

     for j=1:1:TrainClass

    FDA

    Euc_Distance(j,1)=(norm(Gabor_Fisher-aver_

    Fisher(:,j)))^2; function end [T,aver_Fisher,Train_Fisher]=FDA(TrainData _PCA,TrainNum,TrainClass,chara) %class=0; %计算每一类图像的均值 %比较;欧氏; aver=zeros(chara,TrainClass); min=Euc_Distance(1,1); for j=1:1:TrainClass for j=1:1:TrainClass aver(:,j)=mean(TrainData_PCA(:,:,j),2); if end abs(Euc_Distance(j,1))<=min %计算总体的类均值

     2 / 5

aver_matrix=[]; eigen_SB_diag=[];

    for j=1:1:TrainClass KB=eigen_SW_diag^(-0.5)*eigen_SW_vector

     aver_matrix=[aver_matrix aver(:,j)]; '*SB*eigen_SW_vector*eigen_SW_diag^(-0.end 5);%有问题

    aver_whole=mean(aver_matrix,2); [eigen_SB_vector eigen_SB_diag] =

     schur(KB);

    %计算类内散度矩阵

    %S=zeros(6400,6400); %求最终的变换矩阵

    temp_SW=zeros(chara,chara); T=eigen_SW_vector*eigen_SW_diag^(-0.5)*temp=[]; eigen_SB_vector;

    SW=zeros(chara,chara);

    for j=1:1:TrainClass %计算图像经过Fisher变换后的特征

     for i=1:1:TrainNum Train_Fisher=zeros(chara,TrainNum,TrainCla

     ss);

    temp_diff_SW=TrainData_PCA(:,i,j)-aver(:,j); for j=1:1:TrainClass

     for i=1:1:TrainNum

    temp_SW=temp_SW+temp_diff_SW*temp_d

    iff_SW'; Train_Fisher(:,i,j)=T'*TrainData_PCA(:,i,j);

     end end

     SW=SW+temp_SW; end

     temp_SW=zeros(chara,chara);

    end for j=1:1:TrainClass

     aver_Fisher(:,j)=mean(Train_Fisher(:,:,j),%计算类间散度矩阵 2);

    temp_SB=[]; end

    SB=zeros(chara,chara);

    for j=1:1:TrainClass

    PCA temp_diff_SB=aver(:,j)-aver_whole;

     temp_SB=[temp_SB,temp_diff_SB];

     S1=TrainNum*temp_SB*temp_SB'; function SB=SB+S1; [chara,Eigenfaces]=PCA(TrainData,TrainNum temp_SB=[]; ,TrainClass) end %三维向量转二维向量 ratio=0.95 %白化类内散度矩阵 TrainData_PCA=[]; eigen_SW_vector=[]; for i=1:1:TrainClass eigen_SW_diag=[]; for j=1:1:TrainNum [eigen_SW_vector eigen_SW_diag] = schur(SW); TrainData_PCA=[TrainData_PCA,TrainData(:KW=eigen_SW_diag^(-0.5)*eigen_SW_vecto,j,i)]; r'*SW*eigen_SW_vector*eigen_SW_diag^(-0 end .5); end %改变类间散度矩阵 m = mean(TrainData_PCA,2);%计算均值 eigen_SB_vector=[]; %计算协方差矩阵

     3 / 5

A=[]; Gabor_Size=irow*icol;

    for i=1:1:TrainNum*TrainClass result=zeros(irow,icol,Ori/4,Sca);

     temp = double(TrainData_PCA(:,i)) - m; Ori_DownSample=4;

     A = [A temp];

    end %计算Gabor滤波器组

    L = A'*A;%协方差矩阵 for y=-(icol/2-1):1:icol/2 %计算特征值及特征向量 for x=-(irow/2-1):1:irow/2 [V D] = eig(L); for w=1:1:Sca%尺度

    L_eig_vec = []; for n=w:4:w+4%方向

    diag=trace(D); wm=pi/2*2^(0.5-w/2); sum=0; sitan=(n-1)*pi/8; chara=0;

    eig_one_vec=[]; sigma=3*sqrt(2*log(2))/wm; %排序 a=1/(2*pi*sigma^2); %%将对角阵转化为一维向量

    for i = 1 : size(V,2) x0=x*cos(sitan)+y*sin(sitan);

     eig_one_vec=[eig_one_vec,D(i,i)];

    end y0=-x*sin(sitan)+y*cos(sitan); [eig_des_vec,NDX] = DSORT(eig_one_vec);

    %降维 b=exp(-(x0^2+y0^2)/(2*sigma^2)); for i = 1 : size(V,2) %c=cos(wm*x0-exp(-9*lo

     sum=sum+eig_des_vec(i); g(2)));%取实部

     if( sum/diag<ratio)

     %L_eig_vec = [L_eig_vec V(:,i)]; c=exp(wm*x0*i)-exp(-wm^2*sigma^2/2);

     continue; temp=a*b*c;

     end if n<5

     break;

    end result(x+irow/2,y+icol/2,1,w)=temp; chara=i; else

    %得到相应的特征向量

    for j=1:chara result(x+irow/2,y+icol/2,2,w)=temp;

     L_eig_vec =[L_eig_vec V(:,NDX(j))]; end

    end end

    Eigenfaces = A * L_eig_vec; end

     end

    end

    Gabor

    temp1=zeros(irow,icol);

    figure(1); function imshow(uint8(I)); enhan_GaborData=Gabor(I,TrainNum,Sca,Ori ,irow,icol) irow_Gabor=irow*2-1; %%Gabor小波 icol_Gabor=icol*2-1; I_Gabor=zeros(irow_Gabor,icol_Gabor); %定义四维数组

     4 / 5

    I_Gabor(1:irow,1:icol)=I; enhan_GaborData_Row=[]; norm_GaborData=zeros(irow_Gabor,icol_Gabenhan_temp=zeros(irow,icol); or,Ori/4,Sca); for w=1:1:Sca

    GaborData=zeros(irow_Gabor,icol_Gabor); for n=w:4:w+4

     for j=1:1:icol %归一化并显示 if n<5

    j=1;

    figure(2); enhan_temp=norm_GaborData(:,:,1,w); for w=1:Sca else

     for n=w:4:w+4

     if n<5 enhan_temp=norm_GaborData(:,:,2,w);

     temp1=result(:,:,1,w); end

     else

     temp1=result(:,:,2,w); enhan_vector=[enhan_vector;enhan_temp(:,j)]

     end ;

     end

    temp1_Gabor=zeros(irow_Gabor,icol_Gabor);

     temp1_Gabor(1:irow,1:icol)=temp1; enhan_GaborData=[enhan_GaborData,enhan_

     %temp1=result(:,:,n,w); vector];

     %GaborData=abs(conv2(I,temp1)); enhan_vector=[];

     %GaborData = end

    imresize(GaborData,[irow icol]) end

     %enhan_GaborData_Row=reshape(enhan_GaGaborData=ifft2(fft2(I_Gabor).*fft2(temp1_GborData,Gabor_Size*irow_Gabor*icol_Gabor,

    abor)); 1);

     Gabor_Mag=abs(GaborData);

     md=max(max(Gabor_Mag));

     GG=Gabor_Mag/md*255; PCA

     %GG=Gabor_Mag/md;

     %GG=imresize(GG,[irow,icol]);

     if n<5

     norm_GaborData(:,:,1,w)=GG

     else

     norm_GaborData(:,:,2,w)=GG

     end

     subplot(Sca,Ori,j);

     imshow(uint8(GG));

     j=j+1;

     end

    end

%增强Gabor特征

    enhan_vector=[];

    enhan_GaborData=[];

     5 / 5

Report this document

For any questions or suggestions please email
cust-service@docsford.com