Skip to content

πŸ§’πŸ»πŸ‘¨πŸΌπŸ‘±πŸΎβ€β™€οΈπŸ‘ΆπŸ» Face Image Morphing: an OpenCV and NumPy Implementation

Notifications You must be signed in to change notification settings

vectominist/Face-Image-Morphing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

55 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Face Image Morphing

Final project of Interactive Computer Graphics 2020 Spring, NTU CSIE

Introduction

This repository is a simple program for face image morphing implemented in python3. The program can be split into two parts: face feature extraction and 2D image morphing. For the feature extraction part, we used OpenCV and dlib packages following the instructions from the article. While the 2D image morphing program is an implementation of the paper Feature-based image metamorphosis1 in NumPy.

Instructions

Step 1. Download Facial Landmark Detector

Download and decompress the facial landmark detector model from the dlib website.

Step 2. Modify Scripts

Modify the variable shape_pr in scripts run.sh or run3.sh to the path to the facial landmark detector on your computer.

Step 3. Face Image Morphing

Morphing two images

bash run.sh <image 1> <image 2> <ratio> <directory for output images> [name of the morphed image]

Note that the ratio is the interpolation ratio between the two images. ratio = 0 represents the output image will be the first image, while ratio = 1 represents the output image will be the second image.

Morphing three images

bash run3.sh <image 1> <image 2> <image 3> <directory for output images> [name of the morphed image]

The morphing ratio of the three images is set to 33%:33%:33% (ratio_1 = 0.333 and ratio_2 = 0.333). You may set the ratio of the images, if the three images have a interpolation ratio of a:b:(1-a-b), then change the arguments ratio_1 and ratio_2 to a and b, respectively.

Other Methods

Feature Extraction Class

This class is in src/feat_extract.py called FaceFeatureExtractor. The only parameter required is the path to the facial landmark detector model. You may modify the crop_to_face function in the .py file to crop to your desired area.

2D Image Morphing Class

This class is in src/morphing_np.py called Morphing. There are three optional parameters: a, b, and p, controlling the weighting for each line shown in the original paper1.

Experiments

We conducted experiments for verifying whether people are attracted to people who look like them.

The generate.py generate images for the experiment, it can be used as follow:

python3 generate.py <image of tester> <gender m/f> <image dataset> <list of images> <output directory>

The images in the image dataset must be named with beginning of m or f for male or female, respectively. The output images will be stored at the specified directory.

Reference

  1. T. Beier and S. Neely, "Feature-based image metamorphosis", SIGGRAPH, 1992

About

πŸ§’πŸ»πŸ‘¨πŸΌπŸ‘±πŸΎβ€β™€οΈπŸ‘ΆπŸ» Face Image Morphing: an OpenCV and NumPy Implementation

Topics

Resources

Stars

Watchers

Forks