In this project, we explore warping and cross-dissolving techniques in order to change face images.
Defining Correspondences
First we align the photos for warping results using the same align functions from previous projects. Then, we use plt.ginput(0,0) to select keypoints on the aligned images in same sequence for both photos. Then use scipy.spatial.Delaunay to build triangulations from the selected points.
Computing the "Mid-way Face"
To compute the mid-way face, we follow the following algorithm:
find the average of trangulation imgA_pts and imgB_pts to get avg_pts
get the triangulations of the average image using Delaunay
using the average triangulations, warp imgA to the average face, and imgB to the average face
cross-dissolve the resulting two warpped images following the same weight that the images were warped by alpha * warped_imgA + (1 - alpha) * warped_imgB
Warping algorithm:
iterate over each triangle in the list of triangulations
using the destination triangulation indeces, get the corresponding points in src_img and dest_img
find the affine transformation T, solving src = inverse(T) * dest
find all the pixels in within the triangle in the src and dest triangles and apply the inverse transformation to go from the dest location to the src location
map the transformed src pixels to the dest pixels
Below are some of my results:
The Morph Sequence
The morph sequence is essentially repeating the mid-face process except with differing weights at each frame, rather than an average. For mine, I did 20 frames and each frame decreases the weight of the first image from 1 to 0 in decrements of 5% while increasing the weight of the second image in the same manner. I used the same weights for calculating the faces at each frame and for the cross-dissolving.
The "Mean face" of a population
To find the mean face of the population, I took the IMM Face Database and selected the frontal facing images, both smiling and not. Reading in each image and points provided, I found the average of all the faces. Using the average points, warped each individual image to that average and cross-dissolved all the images together to get the below result:
Here are some other population faces warped to the average shape:
Finally, let's warp my face to the average shape and vice versa!
Caricatures: Extrapolating from the mean
We can extrapolate by changing the warping weight of the images from [0,1] to <0 or >1. Below are two examples of -0.2 and 1.2 weight on the first image and 1.2 and -0.2 weights on the second image, respectively.
Bells and Whistles
For Bells and Whistles, I transformed my gender by warping to the average East Asian male.