Docsity

Eigenfaces and Recognition - Assignment 2 | CSCI 1430, Assignments of Computer Science

Toggle sidebar
bg1
CS143: Introduction to Computer Vision
Homework Assignment 2
Eigenfaces and Recognition
Due: October 3 at 10:59am - Problem 1.
Due: October 8 at 10:59am - Problems 2.
Due: October 15 at 10:59am - Problems 3.
The assignment is worth 15% of your total grade.
It is graded out of a total of 100 (plus 10 possible extra points).
Goals.
In this assignment you will use what you have learned about bases, projection,
templates, and eigen-representations. You will also use Gaussian densities and
maximum-likelihood estimation.
This is a simple version of a real problem and consequently uses many of tools
we will learn (though in a simplified form). This assignment might provide a good
base for more advanced projects.
Summary.
You will be working with a training database of face images taken of the class.
You will build a low-dimensional model of the face appearance using Principal
Component Analysis. You will build a simple probabilistic model of faces and
then use this to detect faces in images taken of the whole class.
1
pf3
pf4
pf5
pf8

Partial preview of the text

Download Eigenfaces and Recognition - Assignment 2 | CSCI 1430 and more Assignments Computer Science in PDF only on Docsity!

CS143: Introduction to Computer Vision

Homework Assignment 2

Eigenfaces and Recognition

Due: October 3 at 10:59am - Problem 1. Due: October 8 at 10:59am - Problems 2. Due: October 15 at 10:59am - Problems 3.

The assignment is worth 15% of your total grade. It is graded out of a total of 100 (plus 10 possible extra points).

Goals.

In this assignment you will use what you have learned about bases, projection, templates, and eigen-representations. You will also use Gaussian densities and maximum-likelihood estimation. This is a simple version of a real problem and consequently uses many of tools we will learn (though in a simplified form). This assignment might provide a good base for more advanced projects.

Summary.

You will be working with a training database of face images taken of the class. You will build a low-dimensional model of the face appearance using Principal Component Analysis. You will build a simple probabilistic model of faces and then use this to detect faces in images taken of the whole class.

Files you need.

The face training images that you should work with are in the directory

/course/cs143/data/Faces08/mugs

The individual images that you will use for face detection are located in

/course/cs143/data/Faces08/individual

while the group pictures of the class are in

/course/cs143/data/Faces08/group ‘‘motion_lab.JPG’’ will be used for problem 3; ‘‘classroom.JPG’’ is for extra credit.

Additionally, we provided three Matlab scripts problem[1-3].m in the di- rectory /course/cs143/asgn/asgn2/, which you should start from. Their main purpose is to make it easier for us to grade your homework. You are therefore asked to copy those files and modify them, so that they perform the appropriate task and display your results. You are of course free to write your own scripts and/or functions and only add calls to these from the scripts we provided.

What to hand in.

You will hand in your Matlab code, which is supposed to show all your re- sults, and any text or explanations that are required. Please hand in the modified problem[1-3].m scripts as well as any other Matlab scripts or functions that your solution requires. Make sure that all your results are displayed properly! You will also hand in any text or explanations electronically. They should either be in plain text format, in Postscript, in PDF or in DOC. To handin the assignment run the commands below from the folder that con- tains your solutions. The entire contents of that folder will be zipped and sent to us.

  • First problem:

/course/cs143/bin/cs143_handin asgn2_p

  • Second problem:

%The new ’img’ will be a row vector. imgvec=img(maskInd);

%To put ’img’ back into a matrix tempimg=zeros(maskSz); tempimg(maskInd)=imgvec; imgvec=tempimg;

%Alternately you can do element-wise % multiplication. The resulting image % will have nan’s around the borders img=img.*mask;

  • Display the mean face and the first six principal components (eigen- faces).
  • Show a plot of the cumulative variance.
  • How many bases account for 95% of the variance? What about 80% of the variance? Note: When computing [U, S, V]=svd(A), where A is your data matrix of images, the diagonal elements of S will be the singular values σi. In order to compute variance along each principal direction Ui you need to square the diagonal elements and divide by N − 1 , ie. λi = σ^2 i /(N − 1)
  1. (30pts) Likelihood model.

Using the first M = 6 principal components from above, build an approx- imate probabilistic likelihood model p(x|Ω) where x is a vectorized image patch (x ∈ RN^ ), where N is the size of the region of interest specified by the image mask (ie. from the previous Matlab example, length(maskInd)), and Ω is the object class (faces in this case). Assume that face images can be represented by their mean and covariance. In this case we would have

p(x|Ω) =

(2π)N/^2

det(Σ)−^1 /^2 exp(−

(x − x¯)T^ Σ−^1 (x − ¯x))

where x¯ is the mean face image and Σ is the covariance matrix. The term (x − ¯x)T^ Σ−^1 (x − x¯) is called the Mahalanobis distance.

We can use the eigendecomposition to rewrite Σ as U S^2 U T^ /(N −1), where S and U are the matrices returned by svd(A).

Plugging that into the Mahalanobis distance we get

d(x) = (x − ¯x)T

( U S^2 U T N − 1

)− 1 (x − x¯)

= (x − ¯x)T^ U

( S^2 N − 1

)− 1 U T^ (x − ¯x)

= yT^ Λ−^1 y

where y = U T^ (x−¯x) represents the coefficients of the projection of the data onto the subspace spanned by U T^ and Λ is the diagonal matrix of variances (λi) as computed in the previous problem.

The Mahalanobis distance can now be written as a simple sum (remember that we are building only an approximate model so we are summing from 1 to M = 6):

d(x) =

∑^ M

i=

y i^2 λi

Define the approximate image likelihood using this formula. Also, feel free to ignore the normalization constant.

  • Choose three different looking face training images, project each onto your six dimensional subspace to get vectors of coefficients represent- ing the images. Compute the approximate version of each image using the subspace. Show the original images and the reconstructions. Com- pute the log likelihood of the original image using the approximate model.
  • Draw six random samples from your approximate probabilistic model. Since the covariance matrix is diagonal, you can sample from each of the six directions independently. You can use RANDN in Matlab to do this. Make sure that you multiply these numbers by the corresponding standard deviations

λi along each principal direction. Show each random face and compute its log likelihood using the approximate model.

  • Comment on the random samples. Do they look like faces? If so, why? You might also want to try using more basis vectors.

but you will most likely need to tweak the parameters. In the end, the faces you want to detect should be roughly the same size (judged, for example, by the distance between the eyes) and the same inten- sity (you can check this by using the Data Cursor in Matlab’s figure window) as the mean face.

% Assume I is the image you’re searching in. % For the individual pictures: I = imresize(I,0.36); % Scale correction I = I (^) * 1.3 % Luminosity correction

% For the group image I = imresize(I,1.25); % Scale correction I = I (^) * 1.1 % Luminosity correction.

  • Note that the individual and the group images are color images (no need to worry about the training images; they are already greyscale). To convert color images to grayscale, please use rgb2gray(). For detecting the green background, you could consider converting the im- ages to the YCbCr color space using rgb2ycbcr() and thresholding the chrominance channel Cr.
  • Preprocess all the images by convolving them with a gaussian kernel. This will hopefully make the PCA basis less sensitive to small mis- alignments. Apply plenty of blur to the images you’re searching in to remove noise and make reduce variance in the faces.
  • Crop out a smaller portion of the group image and use that for debug- ging your code. This will save you a lot of time.
  • You can compute the Mahalanobis distance at every pixel without us- ing “for” loops. Consider using “imfilter” instead. Remember that you will be projecting image patches minus the mean face image. Some simple linear algebra lets you subtract off the effects of the mean after projection.

Students seeking graduate credit are not required to complete the extra credit problems in part 3; these may be done for extra credit at your dis- cretion. Instead, graduate students should implement, test, and compare the enhanced distance function defined in Moghaddam & Pentland; that is, use equation 7. The paper is available here:

http://www.cs.brown.edu/courses/cs143/Papers/moghaddam95probabilistic.pdf

(5 extra pts) Apply a multiresolution approach for detecting faces. Construct a 3-level image pyramid of the group image and each of the training images. Com- pute the likelihood at the coarse level. Choose the locations that maximize the likelihood and use these to constrain the search at the next level. Repeat until the finest level. Display an image showing the detected face locations at each level. How much computation is saved by this coarse-to-fine imple- mentation?

(10 extra pts) Get your face detector to work on the classroom images. These are much harder due to the large scale and illumination changes.

(10 extra pts) Once you detected the faces, try to automatically recognize the persons by comparing the projection coefficients of the detected faces to the coeffi- cients of the training images.