# CS194-26: Image Manipulation and Computational Photography

## Project 4: Face Morphing

### Purpose

The purpose of this project was to morph one face into another using Delaunay tringulation. Since we want certain features, such as eyes, noes, ears, etc, to be matched between the two faces, we define correspondances between the two images for a morphing that looks natural.
Once two faces can be morphed successfully, five, fifty, or even hundred faces can be morphed together. By morphing hundred faces of people, we can get a mean face image, which is the average face of the hundred people.
Afterwards, using the average mean face, we can morph the mean face to our own faces. While morphing, instead of morphing between the two faces (as we have done in the previous part), we can morph on the direction of our own faces. this results in our features being more prominent, and therefore creats a caricature of our own faces.

### Part 1: Morphing

#### Defining Correspondences

In this part, the two images of George Clooney and Brad Pitt will be morphed.

In order to morph the two faces to look naturally, we have to set points in a way that they correspond to each other.

The above image shows the order of the points and where it is located in each of the faces.

#### Triangulation

The above left image shows the two faces morphed with a weight 0.5, where weight is: new_img = weight * img1 + (1-weight) * img2
The image on the right shows the Delaunay Tiangles of the image. The triangulation is done on the image with weight 0.5 instead of either image1 or image2, because it is the safest triangulation.
Notice that the jaws are not perfectly morphed because there isn't a corresponding point for the jaws. This can be fixed if points are added on the jaw line.

#### Affine Transform

Afterwards, a new_img, which is the morphed face according to what weight you want, is created by using affine transformation. In each iteration, a transformation matrix is calculated for each triangle to know how image1, new_img, and image2 is mapped to each other.

In the equation, A B C represent the three points in each triangle. The unknown are the values a, b, c, d, e, f, where it can be calculated by multiplying the first matrix with the inverse of the third matrix.
The img2 points can be found by finding the transformation matrix in the same way.

Above is 46 frames of the morphing where weight goes from 1 to 0. Each frame is shown 0.33 seconds.
If gif doesn't move, click: here

### Part 2: Mean Face

In this part, the mean face is found using the data set: https://fei.edu.br/~cet/facedatabase.html

The left shows a sample of the faces that are in the data set and the right shows the points in the face of the data. These datapoints are used to find the average face of a number of people. The faces are morphed just as it is done in Part1.

From left to right, this shows the mean face of 20, 50, and 100 faces. I chose to morph the faces that were smiling because the photo that I want to use of myself is a smiling one.

### Part 3: Caricature

In this part, the caricature of my face is created using the mean face found in Part2. The mean face of 100 faces will be used.

The left is the mean face from Part2 and the right is my face.

The above shows the different faces as the weight changes. The one with the weight = -0.5 is my caricature. You can see that the features that I have are more prominent.

### Bells and Whistles: Face-morphing music video of the students in the class

​In this part, I got together with the the other students in the class to create a face morphing music video.

Above is the part I was responsible for in the music video.