%Simple (partial) implementation of the Adaboost
%Computer Vision (EL3105)
%% load test data
load my_viola_24x24; %X -images, y- {face = 1, nonface = -1}
%% Diaplay training data
%find all the faces
indF = find(y==1);
% Vectorized version
% M = X(:,:,indF);
% M = reshape(M,24,24,1,length(indF));
% Non-vectorized version
tic
M=uint8(zeros(24,24,1,length(indF)));
ii=1;
for kk=indF,
M(:,:,1,ii)=X(:,:,kk);
ii=ii+1;
end
toc
figure, montage(M); %disply all faces in a single image
indnF = find(y==-1);
% Vectorized version
% M = X(:,:,indnF);
% M = reshape(M,24,24,1,length(indnF));
% Non-vectorized version
M=uint8(zeros(24,24,1,length(indnF)));
ii=1;
for kk=indnF,
M(:,:,1,ii)=X(:,:,kk);
ii=ii+1;
end
figure, montage(M); %disply all non-faces in a single image
%% Calculate Haar features
L=15; d1=3; d2=3;
HFs=DefHaarFeature_example(L,d1,d2); %features definition
L=9; d1=2; d2=2;
HFs1=DefHaarFeature_example(L,d1,d2);
HFs = [HFs,HFs1];
% D=9; l1=2; l2=2;
% HFs2=DefHaarFeature_example_V(D,l1,l2);
% HFs = [HFs,HFs2];
%tic
F = zeros(size(HFs,2),size(X,3)); %allocate memery for the computed features
for kk=1:size(X,3),
XX = double(X(:,:,kk));
XX = (XX-mean2(XX))/std2(XX); %image intensity and contrast correction
C = cumsum(cumsum(XX)')'; %integral image calculation
F(:,kk) = HaarFeature(C,HFs); %calculation of the Haar features for image kk
end
%toc
%% Weak classifier
f=F(82,:); %for example select feature number 60
W=ones(1,size(X,3)); %initial weights:
iPos = find(y==1); %indexes to face images
iNeg = find(y==-1); %indexes to non-face images
W(iPos) = 1/length(iPos); %for faces
W(iNeg) = 1/length(iNeg); %for non-faces
tic
TH = -Inf*ones(size(F,1),1);
E = Inf*ones(size(F,1),1);
P = zeros(size(F,1),1);
for kk = 1:size(F,1),
[th,e,p] = WeakLearner(F(kk,:),W,y); %find the weak-classifier
TH(kk) = th;
E(kk) = e;
P(kk) = p;
end
toc
% tic
% [TH1,E1] = WeakLearner_MultiFeature(F,W,y);
% toc
[e,ith] = min(E);
f=F(ith,:);
%display the best Haar pattern
figure;
for kk=1:24,
subplot(4,6,kk);
imshow(X(:,:,kk+20),[]); hold on;
hd = HFs(:,ith);
plot([hd(4)+1,hd(5);...
hd(4)+1,hd(5);...
hd(4)+1,hd(4)+1;...
hd(5),hd(5)],...
[hd(1)+1,hd(1)+1;...
hd(3),hd(3);...
hd(1)+1,hd(3);...
hd(1)+1,hd(3)],'r-');
plot([hd(4)+1,hd(5)],[hd(2)+0.5,hd(2)+0.5],'g-');
end
%disply results for the estimated weak-classifier
Pos = f(iPos);
Neg = f(iNeg);
[PP,bP]=hist(Pos,30);
[NN,bN]=hist(Neg,30);
figure,
plot(bP,PP/length(iPos),'-g'); hold on
plot(bN,NN/length(iNeg),'-r');
plot([TH(ith),TH(ith)],[0,max(NN)/length(iNeg)],'-k');
%% Adaboost
T=5;
[FS,TH,P,A]=CV_adaboost(HFs,F,y,T);
%Dispaly selected features
figure;
for kk=1:16,
subplot(4,4,kk);
imshow(X(:,:,kk+20),[]); hold on;
dispHaarFeature(FS);
end
CV_Assignment.zip_Haar特征提取_adaboost haar_assignment_haar adaboos
版权申诉
116 浏览量
2022-07-15
03:18:34
上传
评论
收藏 6KB ZIP 举报
APei
- 粉丝: 63
- 资源: 1万+
最新资源
- Picasso_v3.1 2.ipa
- chromedriver-mac-arm64.zip
- 蓝zapro.apk
- chromedriver-linux64.zip
- UCAS研一深度学习实验-MNIST手写数字识别python源码+详细注释(高分项目)
- 基于Python和PyTorch框架完成的一个手写数字识别实验源码(带MINIST手写数字数据集)+详细注释(高分项目)
- 基于Matlab在MNIST数据集上利用CNN完成手写体数字识别任务,并实现单层CNN反向传播算法+源代码+文档说明(高分项目)
- NVIDIA驱动、CUDA和Pytorch及其依赖
- 基于SVM多特征融合的微表情识别python源码+项目说明+详细注释(高分课程设计)
- html动态爱心代码一(附源码)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈