91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 31.46MB
    文件類型: .zip
    金幣: 1
    下載: 0 次
    發布日期: 2023-06-21
  • 語言: Matlab
  • 標簽: PCA??降維??人臉識別??

資源簡介

matlab程序提供了相應的論文和測試數據集,實現了基于PCA的人臉識別。并附加了一個更改后的單幅圖片與訓練數據匹配的程序(需要將數據集拷貝進去)。

資源截圖

代碼片段和文件信息

function?[accuracy]=my_face_recognition(?train_dirtest_dirtrain_numtest_numenergyb?)
%該函數實現了利用PCA方法進行人臉識別的過程
%Input
%???????train_dir:訓練數據集的目錄
%???????test_dir:測試數據集的目錄
%???????train_num:選擇的訓練數據集的個數
%???????test_num:要測試的數據集的個數,要小于訓練數據集個數

if?train_num????fprintf(‘訓練數據集要大于測試數據集!\n‘);
????return?;
end


%因為文件大小固定,所以在此我們設置矩陣的行列為定值
row=142;
column=120;
train_data=zeros(train_numrow*column);%預分配數據可以加速數據讀取,矩陣的行數是訓練數據的個數,列數是圖片的維度,建0矩陣
train_files=dir(train_dir);%獲取訓練目錄下的所有文件,獲得的每一個文件都是一個結構體,我們需要的是其中的name屬性。第一個和第二個文件分別表示當前目錄和父目錄,需要跳過

for?i=1:train_num
????file_name=sprintf(‘%s\\%s‘train_dirtrain_files(i+2).name);%這里需要加雙斜杠
????
????img_data=imread(file_name);
???
????%[row?column]=size(img_data);
????img_data=img_data(1:row*column);%將讀取的數據轉成一個行向量
????train_data(i:)=img_data;%將該行向量添加到訓練集中
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%求平均臉,與人臉識別無關,只是一個測試
imgmean=mean(train_data);

size(imgmean);
mean_img=reshape(imgmeanrowcolumn);
mean_img=uint8(mean_img);
%imshow(mean_img);
%imwrite(mean_img‘D:\1.bmp‘);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%{
if?b==1
????for?i=1:test_num
????????train_data(i:)=train_data(i:)-imgmean;
????end
end
%}

%進行主成份分析,返回的結果為
%???COEFF:特征向量
%???latent:特征值,按由大到小的順序排列
%當數據的維度大于數據個數時,通過在函數后面添加參數‘econ’可以加速計算
[COEFF~latent]?=?princomp(train_data‘econ‘);

%保存的維度(特征值)個數使圖像保存的能量大于95%
dimension_left=0;
cum_percent=cumsum(latent)/sum(latent);

for?i=1:length(cum_percent)
????if?cum_percent(i)>=energy
????????dimension_left=i;
????????break;
????end
end
%fprintf(‘dimension?left?is?%d\n‘dimension_left);


%將訓練數據集進行降維
train_data_reduced=train_data*COEFF(:1:dimension_left);

%讀取測試數據集
%test_data=zeros(train_numrow*column);%預分配數據可以加速數據讀取,建0矩陣
test_data=zeros(1row*column);%預分配數據可以加速數據讀取,建0矩陣
test_files=dir(test_dir);%獲取訓練目錄下的所有文件,獲得的每一個文件都是一個結構體,我們需要的是其中的name屬性。第一個和第二個文件分別表示當前目錄和父目錄,需要跳過

%?for?i=1:test_num
%?????file_name=sprintf(‘%s\\%s‘test_dirtest_files(i+2).name);%這里需要加雙斜杠
%?????img_data=imread(file_name);
%?????img_data=img_data(1:row*column);%將讀取的數據轉成一個行向量
%?????test_data(i:)=img_data;%將該行向量添加到訓練集中
%?end

%****************選擇一幅圖片讀入*****************%
???file_test_name=(‘E:\\學習資料\\論文\\圖像\\PCA人臉降維\\人臉識別\\dataset\\Testing\\00020fb010_930831.bmp‘);
???img_data=imread(file_test_name);
???
???figure(1);
???subplot(121);
????
???
???imshow(img_data);
???title(‘測試圖片‘);
????
????
???img_data=img_data(1:row*column);%將一幅圖片轉換成一個行向量
???test_data(1:)=img_data;
%{
if?b==1
????for?i=1:test_num
????????test_data(i:)=test_data(i:)-imgmean;
????end
end
%}

%將測試數據集進行降維
test_data_reduced=test_data*COEFF(:1:dimension_left);

accuracy=0;
%for?i=1:test_num
????%通過計算向量二階范數的方法計算歐式距離
????min=norm(test_data_reduced(1:)-train_data_reduced(1:));
????
????position=1;
for?j=2:train_num
????????distance=norm(test_data_reduced(1:)-train_data_reduced(j:));
????????if?min>distance
????????????min=distance;
??

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-12-08?15:51??PCA單幅圖像匹配\
?????目錄???????????0??2015-12-08?15:51??PCA單幅圖像匹配\matlab\
?????文件????????4673??2015-12-07?23:34??PCA單幅圖像匹配\matlab\my_face_recognition.m
?????文件?????????351??2015-12-07?19:39??PCA單幅圖像匹配\matlab\test_energy.m
?????文件?????????320??2015-12-07?19:38??PCA單幅圖像匹配\matlab\test_face_num.m
?????文件?????????355??2015-12-07?19:37??PCA單幅圖像匹配\matlab\train_face_num.m
?????目錄???????????0??2012-06-03?15:11??人臉識別\
?????目錄???????????0??2012-06-03?15:08??人臉識別\dataset\
?????目錄???????????0??2012-06-03?15:08??人臉識別\dataset\Testing\
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00001fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00002fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00003fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00004fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00005fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00006fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00007fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00008fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00009fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00010fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00011fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00012fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00013fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00014fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00015fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00016fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00017fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00018fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00019fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00020fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00021fb010_930831.bmp
?????文件???????18118??2010-05-24?13:21??人臉識別\dataset\Testing\00022fb010_930831.bmp
............此處省略2374個文件信息

評論

共有 條評論