Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Python facial landmarking and analysis

Project description

pfla: Python Facial Landmark Analysis
[![GitHub release](](
[![PyPI license](](
[![PyPI version](](
[![PyPI pyversions](](
[![Read the Docs](](
[![Build Status](](

Advances in artificial intelligence have enhanced the usability of these
technologies in a clinical setting. This python package introduces the use of a
Detection Outline Analysis (DOA) methodology for facial analysis in dentistry.
This package uses [Haar
cascades]( for
face detection, a trained 68-facial-landmark model and statistical shape
analysis ([300 Faces In-The-Wild](
The software uses an R script to conduct statistical
[shape]( analysis
through a generalized Procrustes analysis (GPA), principal component analysis
(PCA) and non-parametric Goodall test, which compares mean shapes of each group
for significance. The script also computes mean Euclidean distance from a
baseline shape for each landmark.

This package was written to conduct automated facial analyses of patients
affected by Osteogenesis Imperfecta and controls under the BBDC 7701 study. Its
use may also be extended to the study of other dental and/or craniofacial
conditions or to compare different study groups while examining variables such
as sex, ethnicity, etc.

If you use this program or a modified version of it for research purposes
please cite as follows:


: title author year journal



- Takes 2 directories as input containing .jpg (anteroposterior
clinical photographs)
- Image Processing: scales images, transformation to grayscale
- Detection: haar cascade face bounding, 68 facial landmark placement
- Statistical Shape Analysis: GPA, PCA, Goodall's F-test, Euclidean
distance per landmark from baseline shape

Requirements and Dependencies

- Python 3.5 (or higher)
- Python packages: opencv-python, dlib, imutils, numpy, argparse, pandas,
rpy2, progress
- Linux operating system
- R 3.3 (or more or higher)
- R packages: shapes, foreach


Important: in order for the required package rpy2 to install sucessfully, you
will need to have R version 3.3 or higher as well as the packages 'shapes' and

To install with **conda**:

conda env create -f environment.yml
conda activate pfla
mkdir shapes
cd shapes
conda skeleton cran --recursive shapes
conda build r-shapes
conda install -c local r-shapes
pip install pfla

To install with **pip**:

pip install -r requirements.txt
pip install pfla
Then in R
install.packages("shapes", "foreach")


To demonstrate the usage of the program we will be using images from the
Caltech Faces dataset which can be downloaded here
([male]( and

When using pfla, it is important to have your image directories structured in a
similar fashion.

The run the program, in the directory containing the image folders enter the

$ pfla -g1 test_males -g2 test_females

The resulting output from the analysis will be printed out into the
terminal like so:

___ __ \__ ____/__ /___ |
__ /_/ /_ /_ __ / __ /| |
_ ____/_ __/ _ /___ ___ |
/_/ /_/ /_____/_/ |_|
Python Facial Landmark Analysis
Author: Maxime Rousseau

Processing Images |###############################| 10/10
g1 processing completed without errors
Processing Images |###############################| 10/10
g2 processing completed without errors

*Bootstrap - sampling with replacement within each group under H0: No of resamples = 10
null device
[1] --------------------------------------------------------------------------------
[1] Goodall Statistical Test P-Value: 0.363636363636364
[1] --------------------------------------------------------------------------------
[1] Summary of Mean Euclidean Distance:
[1] Group 1:
[1] Mean: 0.00662911513379532 | Standard Deviation: 0.00257462207986629
[1] Group 2:
[1] Mean: 0.00743691647218815 | Standard Deviation: 0.00281889044033377
[1] --------------------------------------------------------------------------------

A histogram summarizing the mean Euclidean distances per landmark will
also be save in the data/ directory.

![Mean Euclidean Distance Histogram](paper/histo_02.png)


To test your installation run the following commands:
cd ~/.local/lib/python3.5/site-packages/pfla/

Documentation of the package can be found here:


- Refer to the contribution guidelines:
- Issue Tracker: <>
- Source Code: <>


The project is licensed under the MIT license.


Maxime Rousseau, DMD II McGill University, Faculty of Dentistry
- Email: <>

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pfla, version 0.2.2
Filename, size File type Python version Upload date Hashes
Filename, size pfla-0.2.2-py3-none-any.whl (3.2 MB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size pfla-0.2.2.tar.gz (148.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page