wiki:recipes/AnalysingMasculinityFromShape

Version 2 (modified by Dave Hunter, 13 years ago) ( diff )

--

Recipe for analysing masculinity from shape

The aim of this tutorial is to allow you create a numerical value that indicates the amount of an attribute a given face has. Consider the case of masculinity/femininity, clearly some faces are more ‘masculine’ than others and a numerical value could in theory represent this. As there is no physical definition of masculinity we learn it from the data and define it as a vector such that moving along the vector in one direction increases the masculinity and moving in the opposite direction increases femininity. Such a vector could be defined between the average male face and the average female face. Moving along the vector towards the average male face increases masculinity, moving along the vector towards the female average increases femininity. A more accurate method of defining masculinity is to use Linear Discriminant Analysis to define the vector between male and female groups.

This tutorial will guide you through the process of generating such statistics, although the exact choice of statistic is up to you. Here we will use LDA but the basic process is the same for most analysis. The process involves preparing faces for analysis in Psychomorph, getting the appropriate values to feed into a statistics package (they tend not be able to take faces as input) and then (optionally) putting the numbers from the stats package back into Psychomorph to generate a face.

Delineation and Alignment

First, delineate all the faces you intend to analyse (if you don't know how to do this look over the other tutorials in this web site). <…Several days later…> The templates you've just painstakingly created will describe the shape of the face in the analysis, so they need to be accurate.

Unless your photographer is perfect, the faces will be moving about in the frame and need to be centred and aligned with respect to each other. Generally, we align the faces to an average, this isn't strictly necessary, you could align the faces to any in your set, but aligning to an average is neater and we need to generate one for later use anyway. So create an average of all the faces in your set (male and female), we will refer to this later as the ‘combined average.’ If you don't know how to create an average check out this tutorial Making averages.

We will now align all the faces in our set to this ‘combined average.’ This will remove translations (i.e. 2D movement), scale and rotation from our data set. First load the average you created a moment ago into the right-hand window of the Psychomorph window. (File->Load Right Image), make sure the combined average template has been loaded along with it. This will be the face template the alignment process will align to (i.e. it can be any delineated face). Under the Edit menu select Batch Align Eyes, you will be presented with a dialog displaying 3 (4 if you include the Cancel option), Eye, Eyes and Mouth, and Full. These indicate the points in the template that Psychomorph will use to align the template to; just the two eye points (i.e. translation and rotation with scale in only one direction); the two eye points and the mouth; and full which uses all the point to perform and alignment (translation, rotation and scale only, unlike Eye, and Eye & Mouth options the points are not exactly matched). Generally we select the ‘Eye & Mouth’ option and this puts the centres of the eyes and the mouth in the exact same place in every image. This alignment should be carried out over every image in the data set (i.e. use the same batch file as for the average). It is good practice to put the new templates and image in a new directory (you don't want to write over all those templates you spent such a long time creating.)

Creating a PCA shape model.

Unless your dataset is exceptionally large (>400) you will have more dimensions in you dataset than sample. If you need to check, the number of dimensions is twice the number of points in your template (i.e. x and y coordinates in the picture), strictly speaking you can subtract up to 6 as a result of the alignment process but that only works if both you and the stats package understand rank-deficient matrices. In order to reduce that number of dimensions, and reduce the chance of over-fitting we use PCA, fortunately shape PCA is built into Psychomorph in the form of an ASM (Active Shape Model).

The Active Shape Model (ASM) describes faces using the extent (and way) they deviate from the average shape. The model finds shape changes that maximise covariance and store these as components. Faces can be described and reconstructed using weighted sums of these components. The weights form the parameters used to describe the faces. As the components are orthogonal (at 90 degrees to each other), the parameters can be manipulated easily to create new faces.

In order to build an ASM, you will need a Batch file containing the names of the aligned templates you created in the previous step. Select Build ASM from the PCA menu. First, you will be asked for a location and name for the ASM model, as the model is actually multiple files it's a good idea to create a new directory for each ASM model you build. Next supply the batch file containing the names of the aligned templates.

The Active Shape Model consists of multiple files.

A .jpg image and .tem template file of the average face shape. A .pca file that contains the shape components used in the model. A .txt file the outputs the eigenvalues of the PCA model in order. And an .asm file that describes the location of the other files.

Analysis with an Active Shape Model

If we wish to use an Active Shape Model to analyse face shapes, we need to generate a set of parameters for each face template. These parameters will describe the face as a weight on each component (or amount of each component). The function ‘Batch Analyse Shape’ will produce a comma separated value file (csv) containing the parameters that describe the shape. Select ‘Batch Analyse Shape’ from the ‘PCA’ menu. First you will need to supply an ASM file (created earlier), next you will be asked to give the name of a file to save the parameters to, avoid selecting the Batch file as it will be immediately overwritten. After this you will need to supply the Batch file containing the image and template files to analyse.

Dimensionality reduction

When carrying out statistical analysis on high dimensional data sets (e.g. templates or images), it is useful and often essential to be able to reduce the dimensionality of the data set. This page will explain how to do this with shape (i.e. template) data, the same basic idea applies to colour (PCI) models.

The components of the ASM model are arranged in order of variance explained. The component that explains the most variance is first, the component that explains the next most variance is second etc. Consequently, the ASM model can be truncated to take the first n components that explains the desired amount of variance.

It is assumed that you have already created an ASM (or PCI) model and used it to analyse a set of templates (or images).

Method

First, we need to find the amount of variance explained by each component. Open the .txt file in a spreadsheet program (in order to open it in excel you may need to rename it to a .csv file). You should get two columns, the first labelled ‘Eigenvector’ simply labels the eigenvectors in order from 0 to 1 minus the number of faces. The second, labelled ‘Eigenvalue’ is the eigenvalue of that particular component. The amount of variance explained must sum to one, so divide each eigenvalue by the sum of *all* eigenvalues to get the variance explained by each component.

Eigenvector Eigenvalue
0 4184.51 =B2/SUM($B$2:$B$164)
1 1485.68 =C2/SUM($B$2:$B$164)
2 1145.03
3 689.22
4 490.41
. .
. .
161 0.34
162 0.29

How you truncate depends on what statistics you wish to analyse, there are two possible methods. One; work out the cumulative variance explained for each component (i.e. the variance explained by that component and all the previous components) and truncate at the component which exceeds the desired amount of variance. Alternatively, you could truncate at the average eigenvalue and keep only those components that individual explain at least average variance.

Truncation of the PCA model involves editing the csv file created by the ‘Batch Analyse Shape’ menu option. In this file each column (except the first which holds the template name) stores weighting value for a particular component, in order of highest variance explained (left) to lowest (right). Values can be truncated by deleting columns after the desired number of components. I.e. if you wish to keep the first 7 components, delete all columns starting with column 8. The remaining 7 columns are the 7 principal components describing the face shape.

By: Dan Re

Put all men and women’s face tems /jpegs in one directory.

Make sure all aligned to same grand average of men and women.

Reducing templates (Updated 20 December 2011)

Used for morphological masculinity analysis, etc.

This recipe is for deleting lines from templates, which is useful for conducting PCA on face shape. We used this to create morphological masculinity scores.

THIS RECIPE WORKS WITH THE NEWEST VERSION OF PSYCHOMORPH, WHICH HAS A PLUGIN CALLED “BATCH BATCH DELETE LINES.”

Step 1: Create a list of jpegs and templates for the images you want to delete lines from (the list would look the same as a list for averaging faces).

Step 2: Create a list of points that you want to delete. You can find the point labels by clicking “View>Draw Labels” in the Transform (single) window. Create the list by naming the points with a space in between. For example, to delete the left and right cheekbone lines in a 3dsk face, you would create the following list:
“164 165 166 167 168 169”.
Make sure to save the list of images and templates and the list of points in the same directory.
Step 3: To batch delete points, go to the Transform window and click “Plugins>Perception Lab.jar>Batch Batch Delete Points.” This will prompt you four times.
Step 4: Open the LIST OF POINTS you want to delete first.
Step 5: Open the LIST OF IMAGES AND TEMPLATES second.
Step 6: Name your output directory
Step 7: Enter a string to append
This should create a new set of templates without the lines for the points you deleted.

PCA

Build asm file

Select menu option (Dual window>PCA>Build Shape PCA (ASM)>Create file name for saving> Open list of trimmed_templates).
Create PCA of shape >n components
Select menu option (PCA>Batch PCA Analyse Shape> ASM file> Save output directory> List of images and tems).
This creates a list of PCA components of decreasing importance (variance explained (see bottom line) and the list has the same order of faces as the list of images and tems

Note: PCA components do not come out in terms of decreasing importance in Psychomorp

Using excel, determine which components in the model explain greater than average variance and truncate the model to include only these.

Stage 3 building shape model predicting sex

Take into spss for regression/discriminate analysis   (incomplete)

Note: See TracWiki for help on using the wiki.