In this project, I aim to successfully face-morph Larry David into my roommate Can, with whom I watch 'Curb Your Enthusiasm' together.
To morph two images, we need to select points of correspondences. I used the given tool to select points on the images. After defining the correspondences, I used Delaney Triangulation to triangulate the mean points of Larry David's and Can Ruso's images to find the mean shape.
Ruso points
David points
Mean points on Can Ruso
In order to compute the mid-way face, we need to find the affine transformation matrix that transforms original points from Larry and Can's images to points in each triangle in the average shape triangulation.
Let's say we have two triangles (one is from one of the original shapes, and one is from the average shape):
Original triangle has points p1, p2, p3, with (xi, yi) coordinates for each point
Transformed triangle has points q1, q2, q3 with (x'i, y'i) coordinates for each point
Then, we can write the following matrix multiplication for the transformation operation, the 1s appended for affine operations:
If we expand this on all 3 points in the triangles:
We can solve this system in matrix form:
Thus, we can use a linear algebra solver to find a, b, c, d, e, and f, and calculate the transformation matrix.
Once we have the tranformation matrix for every triangle, we use inverse warping to warp original images to the average shape. Since I use inverse warping, the corresponding pixels in the source image can be between pixels so I used RegularGridInterpolator to interpolate the pixel values for dissolving. Applying warping to both of the images, and taking the point-wise average of them gives us the average face. This is basically morphing with warp and morph fraction of 0.5.