This project demonstrates how to utilize correspondence points to gradually morph images into one another. The project covers correspondence points, creating a midway-face, generating a morph sequence, finding the mean face of a population, and caricatures.
Me |
Bruce Lee |
Using the provided correspondence tool linked on the project spec, we are able to acquire the points from each image that correspond to the respective location on the other image.
From there, we can use Delaunay from the scipy library to triangulate the correspondence points. Using triplot we overlay the triangles on top of the images as such:
The midway shape was calculated by creating a balanced calculation of the points using a factor warp_frac. These new points can then be triangulated using the same process from the previous step.
Warping the faces into these new positions requires the implementation of solving for an Affine Matrix.
For a given triangle, we can say its matrix contains a row of the triangle's x values, a row of the triangle's y values, and a row of ones concatenated at the bottom.
Matrix A and matrix B are created the same, corresponding to the original image's triangles, and the midway shape's triangles.
These matrices are made such that Ax = B. We can solve for x using linear algebra functions, which is the resulting affine matrix.
Now that we have the affine matrix, we have access to a transition matrix that will translate a point from a triangle to its corresponding position in its destination triangle.
Using skimage.draw.polygon we get access to the indices of all polygons within a triangle. We multiply the affine matrix by each pixel to find its destination.
Me |
Bruce Lee |
Mid-Way Face
The previous section details how to find the intermediate image between two images. We can change warp_frac, the factor for determining the midway shape on a scale to get a gradual process which results in the morph sequence.
For each midway image, we find the warped images from both perspectives and apply dissolve_frac to get a weighted proportion of the images' values.
The mean shape of a population is found by calculating the coordinates of each image's correspondence points. As the library's provided images do not have correspondence points in the corners, they are manually added so that the majority of the image is preserved.
After the mean shape is calculated, Each image is warped along with the mean shape, and the average values of all of the warped images determines the "mean face".
The FEI Face Database was used for this project, which supplied correspondence points for each image.
Mean Face
Some examples of images from the database warped into the "mean face"
Myself warped into the mean face and vice-versa
The results of this are a little janky most likely due to the distance between correspondence points. The face is more centered in the provided images and their hair is fully in view while the top of my head is slightly off of the screen leading to the vertical stretching in the warped image.
A caricature can be made by warping shape wise from a population mean, creating an exaggerated image. This can be done using a factor to determine how much weight would be in finding a midway shape, and a dissolve_frac would be used to determine distortion in the resulting image.
I looked up average images of the female gender on the internet and decided to take an image of the average Southeast Asian female.
Using the correspondence tool from the first part I found the correspondence points corresponding to myself and the Southeast Asian image.
To find the morphed shape we can use the morph function from earlier but set dissolve_frac to 0.
To find the morphed appearance we can use the morph function but set warp_frac to 0
To find the morphed image we do not set either of the factors to 0
Me |
Southeast Asian Female |
Morphed Shape |
Morphed Appearance |
Morphed |