Changes between Version 1 and Version 2 of recipes/AnalysingMasculinityFromShape


Ignore:
Timestamp:
Mar 26, 2012, 8:08:59 PM (12 years ago)
Author:
Dave Hunter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • recipes/AnalysingMasculinityFromShape

    v1 v2  
     1== Recipe for analysing masculinity from shape ==
    12
    2 == Recipe for analysing masculinity from shape ==
     3The 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.
     4
     5This 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 [http://en.wikipedia.org/wiki/Linear_discriminant_analysis 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.
     6
     7== Delineation and Alignment ==
     8
     9First, 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.
     10
     11Unless 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 [wiki:averaging Making averages].
     12
     13We 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.)
     14
     15
     16== Creating a PCA shape model. ==
     17
     18Unless 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).
     19
     20The 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.
     21
     22In 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.
     23
     24
     25== The Active Shape Model consists of multiple files. ==
     26
     27A ''.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.
     28
     29== Analysis with an Active Shape Model ==
     30
     31If 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.
     32
     33== Dimensionality reduction ==
     34
     35
     36When 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.
     37
     38The 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.
     39
     40It is assumed that you have already created an ASM (or PCI) model and used it to analyse a set of templates (or images).
     41
     42== Method ==
     43
     44First, 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.
     45
     46Eigenvector     Eigenvalue[[BR]]
     470               4184.51         =B2/SUM($B$2:$B$164) [[BR]]
     481               1485.68         =C2/SUM($B$2:$B$164) [[BR]]
     492               1145.03 [[BR]]
     503               689.22 [[BR]]
     514               490.41 [[BR]]
     52.               .      [[BR]]
     53.               .      [[BR]]
     54161             0.34   [[BR]]
     55162             0.29   [[BR]]
     56
     57
     58How 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.
     59
     60Truncation 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.
     61
    362
    463By: Dan Re