Name: Catherine Gai
SID: 3034712396
Email: catherine_gai@berkeley.edu
Link to project report website: https://inst.eecs.berkeley.edu/~cs194-26/fa21/upload/files/proj3/cs194-26-aay/catherine_gai_proj3/Project%2003.html
This folder contains six functional python files: "morph.py", "compute_affine.py", "define_features.py", "mean_face.py", "mean_self_transform.py", "change_gender.py".
The folder also contains extra image files: "person_1.jpeg", "person_2.jpeg" (for constructing the morph sequence); "data" directory (for computing the average face); , "person_2.jpg" (for morphing self image to average face and vice versa); "mean_face_man_crop.jpeg", "mean_face_woman_crop.jpeg", "person_2_crop.jpeg" (for gender switching).
This folder also contains a few .csv files that records pre-selected feature points: "person_1_pts.csv", "person_2_pts.csv" (for generating the morph sequence); "self_image_pts.csv" (for morphing between self image and average face); "avg_man_pts.csv", "avg_woman_pts.csv", "self_pts.csv" (for gender switching).
define_features:
This python file contains a function that allows users to choose a certain number of feature points on an image.
- get_points(params): Given the number of features a person wants to choose and the input image, the function records all chosen feature points and return an
$n \times 2$ numpy array, where the first column indicates row coordinates of the feature points, and the second column indicates column coordinates.
compute_affine.py:
This python file contains a function that computes the affine transformation matrix from one triangle to another.
- compute_affine(params): Given the three vertices of triangle 1 and three vertices of triangle 2, the function outputs a
$3 \times 3$ affine transformation matrix that warps triangle 1 to triangle 2.
morph.py:
This python file contains a function and other commands that can generate a midway face as well as a 45-fram morph sequence between two images.
- morph(params): Given source image (im1), destination image (im2), feature points on image 1 (im1_pts), feature points on image 2 (im2_pts), Delaunay triangulation (tri), warp fraction (warp_frac) and dissolve fraction (dissolve_frac), the function outputs a morphed image of im1 and im2, accounting for (1 - warp_frac) of facial structures of image 1, warp_frac of facial structures of image 2; and (1 - dissolve_frac) of texture of image 1, dissolve_frac of texture of image 2.
To generate a midway face and produce a morph sequence, run python morph.py
. You will be prompted with a question that asks if you would like to use existing features. Typing "Y
" would enable the program use "person_1_pts.csv" and "person_2_pts.csv" to morph two images. Otherwise, you would manually pick 62 feature points from either image.
If you choose not to use existing feature points, you would also be asked whether to save your manually selected feature points after visualizing the midway face and morph sequence. Typing "Y
" would enable the program to overwrite current feature points.
mean_features.py:
This python file contains commands that generate an average male face. The average face is generated by morphing 30 male images together.
To generate the average face, run python mean_face.py
. You will be presented with 3 male faces morphed to the average structure, as well as the average face. The average face will be auto-saved.
mean_self_transform.py:
This python file contains commands that morph an individual image to average face; morph the average face to individual face; and create a caricature of the individual's face.
To generate the three images above, run python mean_self_transform.py
. You will be prompted with a question that asks if you would like to use existing features. Typing "Y
" would enable the program use "self_image_pts.csv" to morph two images. Otherwise, you would manually pick 58 feature points from either image.
If you choose not to use existing feature points, you would also be asked whether to save your manually selected feature points after visualizing the morph of individual face to average face and from average face to individual face. Typing "Y
" would enable the program to overwrite current feature points.
change_gender.py:
This python file contains commands that switch gender for a particular individual's face. The gender switch is accomplished by three steps: warping merely the shape, cross-dissolving merely texture, and morphing both shape and texture.
To generate the three images above, run python change_gender.py
. You will be prompted with a question that asks if you would like to use existing features. Typing "Y
" would enable the program use "avg_man_pts.csv", "avg_woman_pts.csv" and "self_pts.csv" to morph two images. Otherwise, you would manually pick 62 feature points from each image.
If you choose not to use existing feature points, you would also be asked whether to save your manually selected feature points after visualizing the gender-switching process. Typing "Y
" would enable the program to overwrite current feature points.