In this project, we used triangulation and affine transformation to morph faces into each other. This was done through taking 2 images, marking corresponding keypoints in each one, and then using that to align the two images together. We then found the average face among a population, then warped our image to that average. Finally, for our bells and whistles, I morphed my face into that of the average NFL player.
I adapted the input code from project 1 to be able to select keypoints. Then, I used Delaunay triangulation to generate triangles across the image.
To compute the midway face, I had to first get the average of the keypoints of myself and Clooney. Then, I used Delaunay triangulation to get the triangles for the image. For each of the triangles and over each original image, I would use the the average keypoints involved in each triangle corner and the corresponding keypoints of the original image to calculate a transformation matrix between the original image triangle and the average image triangle. If A is my average points, C are my input points, and B is the transformation matrix from C to A, we can see that A = B*C, and so B = A * inv(C). We performed this calculation to get all of the transformation matrices. After this, I used polygon to get all the coordinates within each average triangle, and then use my matrices to reproject them to the original image. Then, I used RectBivariateSpline to sample from the original image, and put those sample points into the new image. I did this for both images, multiplying by 0.5 for each to account for the fact I'm adding in 2 images, and I got my results below.
For the morph sequence, I made my code from before more generic, where I could specify 2 images, and then a warp fraction between them and a dissolve fraction between them which would give me a weight to apply with respct to which image to show more and which image to warp more. I went linearly from 0 to 1 for both warp and dissolve, and the results are below!
To compute the mean face of the population, I used the Dane face dataset, specifically looking for male images facing forward. I modified my code from before to be able to take any number of images and average between all of them, giving them equal warp and dissolve weight, and calculating matrices for each of them. My results are below! First I have the average face, then some images from the dataset and their warp into the average face, then my image warped into the average face, then the average faced warped into mine
For the caricature I just did the same thing as warping but made the warp fraction either greater than 1 or less than 0, which produced interesting results.
For the bells and whistles section, I chose to morph my face into the average NFL player, to see what it would be like to be an elite athlete. I also morphed the average NFL player into me. Finally, I did a 50-50 morph.