
Figure 2: The wavelet decomposition for the cat (on the left) and the dog (on the right) is dis-
played. The Haar wavelet was effective in detecting the edges in each picture. This indicates
that even these low resolution images will be useful in a classification algorithm.
Linear Discriminant Analysis
Following the wavelet decomposition, the data is now ready for Linear Discriminant Analysis.
The LDA algorithm is described more in depth in the report on Question 2, but in summary the
algorithm will attempt to find a basis set that maximizes the distance between the two different
classes in space (while minimizing the distance between intra-class samples). In this analysis,
we will make use of the SVD in order to extract the dominant modes of each decomposed image.
The following MATLAB code comprises the catdog_trainer.m function, which will perform the
LDA and output results.
Listing 3: Matlab Code – Training algorithm for cat and dog images
1 function [ sortcats,sortdogs,result,w,U,S,V,th ] = catdog_trainer( cats, ←-
dogs, feature, plots )
2 %Linear Discriminant Analysis for training images of cats and dogs
3 n1 = length(cats(1,:)); n2 = length(dogs(1,:));
4
5 [U,S,V] = svd([cats, dogs], 0); %reduced SVD
6 sounds = S
*
V‘;
7 U = U(:,1:feature);
8 cats = sounds(1:feature, 1:n1);
9 dogs = sounds(1:feature, n1+1:n1+n2);
10
11 if(plots)
12 figure
13 subplot(2,1,1)
14 plot(diag(S), ’ko’,’Linewidth’,[2])
15 set(gca, ’Fontsize’,[14],’Xlim’,[0 80])
16 subplot(2,1,2)
17 semilogy(diag(S),’ko’,’Linewidth’,[2])
Assignment № 3 Page 3