Skip to content

SourCherries/auto-face-align

Repository files navigation

Automatic Face Alignment (AFA)

Carl M. Gaspar & Oliver G.B. Garrod

You have lots of photos of faces like this:

But you want to line up all of the faces like this:

Perhaps you would also like to window the faces to show only inner facial features like this:

All of the above can be done using AFA like this:

import alignfaces as afa

faces_path = "/Users/Me/faces_for_my_study/"
afa.get_landmarks(faces_path)
aligned_path = afa.align_procrustes(faces_path)
afa.get_landmarks(aligned_path)
the_aperture, aperture_path = afa.place_aperture(aligned_path)

To better understand how to write a script for your specific purposes, we direct you to demo 1. Demo 1 also describes how AFA alignment works.

All of these functions depend on reliable detection of facial landmarks, which is provided by the DLIB library. Alignment is based on generalized Procrustes analysis (GPA), which extensively unit tested.

Additional functions (warping)

Automatic landmark detection means that it is also easy to separate shape and texture in order to produce various kinds of warped images.

AFA provides functions for two types of face-warping manipulations common in face perception research.

Morphing between faces

To learn how to do this please see demo 2.

Enhanced average of facial identity

To learn how to do this please see demo 3.

Setup

It is highly recommended that you have conda installed, preferably miniconda rather than full fat anaconda.

If you do have conda, then do the following to install:

conda create --name myenv conda-forge::dlib "python>=3.9" scikit-image

conda activate myenv

pip install "alignfaces @ git+https://git@github.com/SourCherries/auto-face-align.git"

This will create a new virtual environment called myenv. You can use another name for that. You'll need to activate this environment using conda activate myenv whenever you want to use AFA. To deactivate, simply type conda deactivate myenv.

Windows users may encounter a problem with plotting. That is a general issue with Matplotlib on Windows. To fix, simply type the following while your myenv is activated:

conda install freetype=2.10.4

How well does this work?

In addition to unit-testing critical computations, I evaluated both landmark estimation (DLIB) and the outcome of the entire alignment procedure using various face databases. The results are described here.

Citation

If you use this package for your research, please cite the following preprint:

Gaspar, C. M., & Garrod, O. G. B. (2021, November 8). A Python toolbox for Automatic Face Alignment (AFA). Retrieved from psyarxiv.com/erc8a

DOI:

10.31234/osf.io/erc8a

License

This module is under an Apache-2.0 license.

About

Automatically align face images πŸ™ƒβ†’πŸ™‚. Can also do windowing and warping.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published