-
大小: 16.95MB文件類型: .zip金幣: 1下載: 0 次發布日期: 2023-07-26
- 語言: Matlab
- 標簽:
資源簡介
matlab開發-用PCA檢測平面圖像的眼鏡。用主成分分析法檢測人臉圖像中眼鏡的存在
代碼片段和文件信息
%main
clear?all
clc
close?all
%Author:?Mahmoud?Afifi?-?York?University
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%STEP?1
%Load?data?and?calculate?the?mean?face
%load?data
display(‘loading?data...‘);
[eyeglassesnonEyeglassestrainingEtrainingNtestingEtestingN]=load_data();
%calculate?the?average?face
display(‘calculate?the?average?face...‘);
avg_face=getAvgFace(trainingN);
%get?the?size?of?the?original?images?(all?datasets?have?images?with?the
%same?dimensions)
img_size=[size(trainingN2)size(trainingN3)];
%get?the?number?of?samples?in?the?training?data
n=size(trainingN1);
%Too?much?figures..ask?for?closing?figures?of?step1
choice?=?questdlg(‘would?you?like?to?close?all?figures?of?step1?‘?...
????‘Step1‘?...
????‘Yes‘‘No‘‘No‘);
%?Handle?response
switch?choice
????case?‘Yes‘
????????close?all
end
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%STEP?2
%get?principle?components?W?and?the?N?latent?coordinates
%resize?data?to?be?(height*width)xN?matrix
train_imgs=(reshape(trainingN[size(trainingN1)size(trainingN2)*...
????size(trainingN3)]))‘;
glasses_imgs=(reshape(trainingE[size(trainingE1)size(trainingE2)*...
????size(trainingE3)]))‘;
test_imgsN=(reshape(testingN[size(testingN1)size(testingN2)*...
????size(testingN3)]))‘;
test_imgsE=(reshape(testingE[size(testingE1)size(testingE2)*...
????size(testingE3)]))‘;
avg_face=avg_face(:);?%resize?the?mean?to?be?(height*width)x1?vector
display(‘calculate?the?principal?components...‘);
[WXL]=PCA_(train_imgsavg_face);?%get?the?principle?components
%get?the?bound?of?x?axis?in?plots
m=length(L);
%Scree?Plot
figure;
plot(L);
title(‘Scree?Plot‘);
ylim([-200max(L(:))])
xlim([-50m])
xlabel(‘Index?of?Eigenvalues‘)?%?x-axis?label
set(gca‘XTickLabel‘num2str(get(gca‘XTick‘).‘))?%to?avoid?x10^k
ylabel(‘Eigenvalues‘)?%?y-axis?label
set(gca‘YTickLabel‘num2str(get(gca‘YTick‘).‘))?%to?avoid?x10^k
print(‘visualization\\ScreePlot‘‘-dpng‘);??%save?it
%Fraction?of?Variance?(FVE)
FVE=cumsum(L(:))/sum(L(:));?%calc?FVE
%plot?FVE
figure;
plot(FVE);
title(‘Fraction?of?Variance?Explained‘);
xlabel(‘c‘)?%?x-axis?label
ylabel(‘FVE‘)?%?y-axis?label
ylim([min(FVE(:))1])
print(‘visualization\\FVE‘‘-dpng‘);??%save?it
%Plot?first?10?principle?components?(Eigenvectors)
figure(‘units‘‘normalized‘‘outerposition‘[0?0?1?1])?%full?screen
for?i=1:10
????subplot(25i);
????imshow(reshape(W(:i)img_size(1)img_size(2))[]);
????colormap(jet);
????title(sprintf(‘Eigenvector?%d‘i));
end
print(‘visualization\\10EigenVectors‘‘-dpng‘);?%save?it
%reconstruct?the?data
%pick?random?image
num=round(rand*n-1)+1;
%reconstruct?the?original?images?using?few?number?of?basis?vectors
figure(‘units‘‘normalized‘‘outerposition‘[0?0?1?1])?%full?screen
j=2;
subplot(251);
imshow(reshape(train_imgs(:num)img_size(1)img_size(2))[]);
title(
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????12011??2019-01-03?21:10??demo.m
?????文件????????1014??2019-01-03?21:10??for?submission.txt
?????文件????????1047??2019-01-03?21:10??getAvgFace.m
?????文件????????2604??2019-01-03?21:10??load_data.m
?????文件?????4091478??2019-01-03?21:10??logo.jpg
?????文件????????1885??2019-01-03?21:10??PCA_.m
?????文件?????????913??2019-01-03?21:10??ReadMe.txt
?????文件????13845639??2019-01-03?21:10??Report.pdf
?????文件????????1482??2019-01-03?21:10??license.txt
評論
共有 條評論