• 大小: 4KB
    文件类型: .m
    金币: 1
    下载: 0 次
    发布日期: 2021-05-31
  • 语言: Matlab
  • 标签: ICA  人脸识别  

资源简介

此资源是二维对称图像矩阵ICA人脸识别MATLAB源程序,运行效率较高,只需更改训练样本路径即可运行

资源截图

代码片段和文件信息

function [F]=Sym_ICA1(varargin)


%此函数为基于对称图像矩阵的ICA人脸识别方法,其中训练样本为
%ORL库中前20组的前五幅图像。
%输入(即测试样本)为前20组的后五幅图像,输出为与输入匹配的
%训练样本



%%%%%%%%%%%%%%%%%%%%%%%%%%  初始化  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
clc;clear all;close all; 
 I1=imread(‘F:\project\ONE\king\try\ORL\s1\1.bmp‘);
 [ab]=size(I1);
 A=cell(ab);
 B=cell(ab);
 Ae=cell(ab);
Ao=cell(ab);
I=cell(a*b1);
 N=20;
 M=1;
%%%%%%%%%%%%%%%%%%%%%%%%%%图像读入,求镜像图像 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
for i=1:N
    for j=1:M
    A{(i-1)*M+j}=imread(strcat(‘F:\project\ONE\king\try\ORL\s‘num2str(i)‘\‘num2str(j)‘.bmp‘));
    [heightwidth]=size(A{(i-1)*M+j});
    tform=maketform(‘affine‘[-1 0 0;0 1 0;width 0 1]);
    B{(i-1)*M+j}=imtransform(A{(i-1)*M+j}tform‘nearest‘);
     Ae{(i-1)*M+j}= (A{(i-1)*M+j}+B{(i-1)*M+j})/2;
     Ao{(i-1)*M+j}= (A{(i-1)*M+j}-B{(i-1)*M+j})/2;
    end;
 end;
 for  num=1:N*M
     I{num}=reshape(A{num}[a*b 1]);
      X(:num) =I{num};
 end

 
 %%%%%%%%%%%%%%%%%%%分别对奇对称图像矩阵和偶对称图像矩阵求均值%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 Xe= 0;
  Xo= 0;
 for i=1:N*M
    Xe= Xe+Ae{i};
    Xo= Xo+Ao{i};
 end 
Xe=Xe/N;
Xo=Xo/N;

 %%%%%%%%%%%%%%%%%%%对称样本矩阵的协方差矩阵%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 Ge= 0;
 Go= 0;
 for i=1:N*M
   Ge=Ge+double((Ae{i}-Xe)‘)*double(Ae{i}-Xe);
   Go=Go+double((Ao{i}-Xo)‘)*double(Ao{i}-Xo);
 end 
Ge=Ge/(N*M);
Go=Go/(N*M);

%%%%%%%%%%%%%%%%%%%ICA中的数据白化预处理%%%%%%%%%%%%%%%%%%%%%%%%%%% 
[EeDe]=eig(Ge);
Vee=De^(-1/2)*Ee;
[EoDo]=eig(Go);
Voo=Do^(-1/2)*Eo;
KK=zeros(bb*(a-1));
Ve=[Vee KK];
Vo=[Voo KK];
for i=1:N*M
    Ye=double(Ve)*double(X);
    Yo=double(Vo)*double(X);
end

%%%%%%%%%%%%%%%%%%%采用快速固定点迭代法算法计算解混矩阵分别计算Wde 和Wdo%%%%%%%%%%%%%%%%%%%%%%%%%%% 

[xy]=size(Ye);
maxcount=10000;
critical=0.00001;
 Wde=rand(x);
  for n=1:x
       w=Wde(:n);
       count=0;
       Wde(:n)=Wde(:n)/norm(Wde(:n));        lastwp=zeros(x1);

       while abs(w-lastwp)&abs(w+lastwp)>critical
                 count=count+1;
                 l

评论

共有 条评论