Momocs-Outline Analysis Using R
Momocs-Outline Analysis Using R
Abstract
We introduce here Momocs, a package intended to ease and popularize modern mor-
phometrics with R, and particularly outline analysis, which aims to extract quantitative
variables from shapes. It mostly hinges on the functions published in the book entitled
Modern Morphometrics Using R by Claude (2008). From outline extraction from raw
data to multivariate analysis, Momocs provides an integrated and convenient toolkit to
students and researchers who are, or may become, interested in describing the shape and
its variation. The methods implemented so far in Momocs are introduced through a
simplistic case study that aims to test if two sets of bottles have different shapes.
1. Introduction
field, geographers would like to test if differences in the shape of cities can be attributed to
external factors such as highways crossing them or oceans bordering them. In addition, mor-
phometrics, the so-called quantitative study of form, and derived techniques such as shape
clustering and recognition, can concern a wide spectrum of disciplines.
Morphometrics aims at analyzing the variation and covariation of the size and shape of objects,
defining altogether their form. Shape and form might be confusing words, used as synonyms
in many languages. Hereafter, we will use the definition of shape proposed by Kendall (1989)
and Small (1996) that it is “the total of all information invariant under translations, rotations,
and isotropic rescaling”. What remains if we draw a heart, and then rotate the page, or change
its size uniformly, or move the page about on the desk, is the shape of the heart. Shape by
essence is better described in three dimensions, except for flat objects (see Kendall 1989,
for a review). In this paper, however, only two dimensional shape will be considered, e.g.,
three-dimensional objects will be viewed from one side and considered as represented by their
projections on a plane.
How to quantify the shape of the heart that was described above, and how to compare a
given number of hearts to show variations among themselves? This paper aims to provide
a didactic introduction to the shape concept, and particularly a branch of morphometrics
relying on outline analysis. Finally, a case study of outline analysis is presented; it uses
Momocs, the R package presented here, whose name stands for modern morphometrics, and
is intended to simplify such morphometrical analyses.
•
•
•
•
•
•
•
•
Figure 1: These popular D’Arcy Thompson’s fishes illustrate his central thesis: “An organism
is so complex a thing, and growth so complex a phenomenon, that for growth to be so uniform
and constant in all the parts as to keep the whole shape unchanged would indeed be an unlikely
and an unusual circumstance. Rates vary, proportions change, and the whole configuration
alters accordingly” (cited from Thompson 1917). From a morphological point of view, these
two fishes seem very different, but a little change in the growth rate of the caudal (right) part,
here illustrated by the grid and four particular points taken on it, leads to dramatic change.
This example serves to demonstrate that, by providing a rigorous method of describing shape,
morphometrics can help a better understanding of how entities in nature function. Redrawn
after Thompson (1917).
Godelle, Raymond, and Claude 2010), to provide complementary information in the shape
description of watersheds where only scalar indices are classically used (Bonhomme, Frelat,
and Gaucherel 2013a) and the first evidence of intraspecific variability in the shape of pollen
grains of anemophilous species (Bonhomme, Prasad, and Gaucherel 2013b).
At the other end of the XXth century, computerized data acquisition and treatment arose
synchronously with an array of new methodological developments and these techniques of
modern morphometrics revolutionized the historical scope of morphometrics (Rohlf and Slice
1990; Rohlf and Marcus 1993; Adams, Rohlf, and Slice 2004).
• •
•
2
•
•
3 •
• •
1
3
• •
1
•
2
• • •
Figure 2: Two biological shapes that can be explored with modern morphometrics. The mouse
jaw on the left, redrawn after Claude (2008), exhibits many potential landmarks. Some of
them are (1) frontiers between bones, (2) sharp angles on a single bone, and (3) the region
with high curvature. The same approach cannot be easily applied with the Ginko biloba leaf
on the right since less landmarks can be identified or are not consistently present on Ginko
leaves, for instance the separation between the two lobes. Outline analysis can become a
solution in cases such as this.
euclidean distances (Richtsmeier, Cheverud, and Lele 1992; Richtsmeier, Burke Deleon, and
Lele 2002). The landmarks need to be structurally similar (ideally homologous) between
individuals. For instance, if the variation of the vertebrate skull is considered, the bones
that share a common origin are defined as homologous and can be part of a configuration
of landmarks along with any other geometrical feature that can be unambiguously identified
(Figure 2, see also Macleod 1999, for a general discussion on homology).
Other objects, for instance a leaf, do not display any or display too few landmarks. Methods
for analyzing configurations of landmarks cannot be easily applied here, and outline analysis
will be used instead. This second approach considers outline as a whole. Outline is defined
here as the closed polygon formed by the (x; y) coordinates of pixels defining it. One popular
outline analysis approach, on which Momocs is focused so far, uses Fourier series to describe
shapes, and is detailed below. Finally, three dimensional surfaces or outlines are an other
area of morphometrics, but will not be considered here.
(2012). Outline analyses can be performed by some standalone programs but often not under
an open license and only on certain operating systems. The Stony Brook University webpage
lists most of them ([Link] the SHAPE suite by Iwata, Ne-
sumi, Ninomiya, Takano, and Ukai (2002) being broadly used. Momocs is placed under the
GPL license and through this license, it may become a collaborative hub for other researchers
to explore new methods or implement existing approaches.
Tangent angle
6
400 5 16 17 50 2
4 18 19 20 1 7
2 3 15 8
10 19 20
300 6 10 11 −150 2 9 20
12 13 11 18
12
200 7 −350 3 13 14 19
14 16 17
4 8 9 14 15
15 16 18
100 −550 6 7
8 9 13 17
5 10
0 −750 11 12
0 5 10 15 20 0 5 10 15 20
Points along the outline Points along the outline
Figure 3: Twenty equidistant points have been sampled, starting from the beak, counter-
clockwise and along the curvilinear abscissa of the dove shape (top left) outline, inspired by
Picasso’s drawing. This outline can be described using Fourier-based methods. Tangent angle
(top right) illustrates the variation of the tangent angle along the outline. Radius variation
(bottom left) illustrates the length of the radius, here considered as the distance between
the center of the shape (the cross within the dove outline) and the points along the outline.
Elliptical analysis (bottom right) shows the two curves corresponding to xn − x1 (in blue) and
yn − y1 (in red).
the outlines are thus quantified and can be analyzed with classical multivariate tools. The
following sections detail the core functions of Momocs, and an extensive description can be
found in Rohlf and Archie (1984) and Claude (2008).
k
1 X
r(θ) = a0 + an cos(wn θ) + bn sin(wn θ)
2
n=1
with:
p p
2X 2X
an = ri cos(nθi ), bn = ri sin(nθi ),
p p
i=1 i=1
Journal of Statistical Software 7
and:
r p
2X
a0 = ri .
p
i=1
w refers to the pulse and p is the number of sampled points along the outline (equivalent here
to the number of sampled radii in this case). The an and bn harmonic coefficients, extracted
for every individual shape, can be used for multivariate analyses to compare a set of outlines.
and:
r p
2X
a0 = φ(t)
p
i=1
with:
ZT ZT
2 2
an = + x(t) cos(nωt)dt, bn = + x(t) sin(nωt)dt.
T T
0 0
Similarly,
+∞
c0 X
y(t) = + cn (cos nωt) + dn (sin nωt)
2
n=1
with:
ZT ZT
2 2
cn = + y(t) cos(nωt)dt, dn = + y(t) sin(nωt)dt.
T T
0 0
Since the outline contains a finite number of points given by k, one can calculate discrete
estimators for every harmonic coefficient of the nth rank:
k
T X ∆xp 2πntp 2πntp−1
an = 2 2 cos − cos ,
2π n ∆tp T T
p=1
k
T X ∆xp 2πntp 2πntp−1
bn = 2 2 sin − sin .
2π n ∆tp T T
p=1
∆x1 = x1 − xk and cn and dn are calculated similarly. a0 and c0 correspond to the estimate
of the coordinates of the centroid of the original outline and are estimated by:
p p
2X 2X
a0 = xi , c0 = yi .
T T
i=1 i=1
Intuitively, for all positive integers n, the sum of a cosine curve and a sine curve represent
the nth harmonic content of the x and y projections of the k-edged polygon, and for any
n, these two curves define an ellipse in the plane. Ferson, Rohlf, and Koehn (1985) noticed
that in the “time”, say one period, it takes the nth harmonic to traverse its ellipse n times,
the (n + 1)th harmonic has traversed its own ellipse n + 1 times (Figure 4). Ferson et al.
(1985) noticed that the reconstruction of the original polygon is done by vector-adding these
ellipses for all harmonics, which echoes (the ancient astronomer) Ptolemy’s epicycles, and the
reconstruction obtained from N harmonics is the best possible fit in a least-squares sense.
In elliptic Fourier analysis, four coefficients per harmonic are obtained, two for x and two for
y. We can use the first harmonic, the one that defines the best-fitting ellipse, to normalize the
harmonic coefficients and make them invariant to size and rotation. The harmonic coefficients
can also be normalized for the location of the first outline coordinate. When this is done, the
shapes are individually aligned according to their first fitted ellipse. If at least one homologous
point can be defined, one can rather use them to align the outlines. Normalized elliptic Fourier
coefficients, further symbolized by An , Bn , Cn and Dn , are obtained:
An B n 1 cos ψ sin ψ an bn cos nθ − sin θ
=
Cn D n λ − sin ψ cos ψ cn dn sin nθ cos nθ
Journal of Statistical Software 9
Figure 4: For all positive integers, the sum of a cosine curve and a sine curve defines an
ellipse in the plane. Elliptic Fourier analysis is based on an harmonic sum of such ellipses
as in Ptolemy’s astronomical system with higher harmonic order ellipses “rolling” within all
lower order ellipses. Three harmonics are here shown at four locations on the original outline.
The scale λ is estimated as the magnitude of the semi-major axis of the ellipse as defined by
the first harmonic. The second right term corresponds to the orientation of the first ellipse,
with ψ being the rotation angle, the third to the original harmonic coefficient, and the last to
the rotation of the starting point to the end of the ellipse, with a rotation angle of θ. Ferson
et al. (1985) also supplied the following formulas with which to calculate these parameters:
2 × (a1 b1 + c1 d1 )
ψ = 0.5 arctan
a21 + c21 − b21 − d21
with first p
λ = a∗2 + c∗2
and
θ = arctan(c∗ /a∗ )
with
a∗2 = a1 cos ψ + b1 sin ψ
c∗2 = c1 cos ψ + d1 sin ψ
Preliminaries
Momocs is S4-oriented (Chambers 1998) which has many advantages in terms of usage and
10 Momocs: Outline Analysis Using R
whisky
beer
programming: it prevents typing errors, provides validity checking, allows inheritance and
encapsulation, etc. (see Genolini 2008). In practical terms, lists of coordinates and matrices
of harmonic coefficients, are handled through ‘Coo’ and ‘Coe’ class objects respectively, to
which methods can be applied. For those not familiar with S4 objects, data stored in objects
can be retrieved and used as classical S3 objects in R: matrices, factors, etc. The Momocs
documentation provides an extensive description of these classes and the methods that can
be applied to them. The case study presented below will focus on the basic (and probably
typical) use of the package.
All the following examples are based on the bottles dataset from the package (see ?bot and
Figure 5). We want to test if whisky and beer bottles have different shapes. How to calibrate
outline analysis parameters and then obtain a matrix of normalized harmonic coefficients will
also be discussed. While elliptic Fourier analysis will be presented because it is one of the most
popular outline analysis tools today, the methodology employed will be equally valid for other
approaches as well. On the extracted harmonic coefficients, some multivariate analyses will
be presented: principal component analysis and morphological space, to illustrate the global
bottle diversity, and multivariate ANOVA, to test for shape difference between the two sets
of bottles. Then, linear discriminant analysis and hierarchical clustering will be introduced as
perspectives for Momocs and because they are common and helpful statistical tools for those
interested in multiple comparison. Finally, thin plate splines analysis will be introduced: this
is not only a tribute to D’Arcy Thompson’s work but it may also bring great insights into the
developmental differences underlying differences in the shapes compared.
Journal of Statistical Software 11
R> library("Momocs")
R> data("bot", package = "Momocs")
R> panel(bot, cols = rep([Link](2), each = 20))
R> bot
General
--------------------
- 40 outlines
- 1864 +/- 371 coordinates per outline
- No landmark defined
- All outlines are closed
- 1 grouping factor(s) defined
Coordinates: @coo
--------------------
[,1] [,2]
[1,] 37 561
[2,] 37 560
[3,] 37 559
[4,] 37 558
[...]
12 Momocs: Outline Analysis Using R
Factors: @fac
--------------------
type : beer whisky
Through deviations
A qualitative approach would be of limited value, quite unlike the method we have presented
to quantify deviations. The idea is to define, for a given number of sampled points, the best
possible fit (i.e., obtained with half this number of points), and to then compare the euclidean
distances obtained with a lower number of harmonics for every point of this outline and the
best possible outline with these sampled points (Figure 7). One can for instance choose the
minimal number of harmonics that leads to an average deviation of 1 pixel.
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35
36 37 38 39 40 41 42
43 44 45 46 47 48 49
Figure 6: The “pecheresse” beer bottle in the bot dataset reconstructed from different numbers
of harmonics. Twelve harmonics give a very satisfactory reconstruction and for 20 the result
is almost perfect.
3
Deviation in pixels
0
10 20 30 40 50 60
Points sampled along the outline
Figure 7: The bottles dataset included in Momocs and analyzed here. The y-axis represents
the deviation in pixels between the best possible fit with a given number of harmonics (here
32) for every sampled points along the outline (on the x-axis). Standard deviations for the
40 shapes are displayed.
14 Momocs: Outline Analysis Using R
1.0
Quantiles
0
0.5
1
0.8
Cumulative harmonic power
0.6
0.4
0.2
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Number of harmonics included
40 outlines
Figure 8: Cumulated harmonic Fourier power calculated from the bottles dataset. The 12
first harmonics gather nearly 100% of the harmonic power. Maxima and medians are also
plotted.
that we must select, so their cumulative power gathers 99% of the total cumulative power
(Crampton 1995, Figure 8). The power of a given harmonic is calculated as:
R> hpow(bot)
matrix is obtained along with grouping factors, individual names, etc. and returned as a ‘Coe’
class object. By default, the obtained coefficients are normalized so that the first fitting ellipse
is re-aligned along the x-axis. Other options can be considered, for instance, one can also
normalize by performing a Procrustes alignment when landmarks can be defined (see Friess
and Baylac 2003, ?ProcGPAlign and the package’s vignette which includes an illustration of
this approach).
General
--------------------
- 40 outlines
- 20 harmonics
- 1 grouping factor defined
[...]
Before multivariate analysis can be performed, one may be interested in having a global view
of the elliptic Fourier analysis: which coefficients vary and what is the geometrical variation
they depict (Figure 9). For instance, bn and cn represent the asymmetry of the shapes that
can vary from coarse to fine scales, i.e., from lower to higher rank harmonics (Iwata, Niikura,
Matsuura, Takano, and Ukai 1998; Yoshioka, Iwata, Ohsawa, and Ninomiya 2004). Figure 9
is obtained by typing:
Harmonic contribution
0
0.5
Amplification factor
1
2
5
10
1 2 3 4 5 6 7 8
Harmonic number
Harmonic coefficients
A
B
C
D
0.05
Coefficient value
0.00
−0.05
−0.10
−0.15
2 3 4 5 6 7 8
Harmonic number
Figure 9: Analysis of harmonic coefficients after an elliptic Fourier computation on the bot
dataset. The top figure shows the effect of every harmonic on the shape reconstruction. Every
harmonic is represented on the x-axis; then the corresponding coefficients are multiplied by
values that illustrate their removal (0), the normal shapes they lead to (1) or their exaggerated
effect in shape reconstruction (2 and above). When the first harmonic is removed, on which all
other ellipses “roll on”, the reconstructed shape is obviously very bad. Exaggerated coefficients
help to understand their contribution to the final shape, e.g., the second harmonic multiplied
5 or 10 times indicates that it contributes to describe the bottleneck while the third and
fourth harmonic contribute to the constriction on the middle of the bottle. The bottom figure
illustrates the variation of every coefficient along the whole dataset. Here, both the Bn and
Cn coefficients are very small depicting the (bilateral) symmetry of the studied shapes.
Journal of Statistical Software 17
Principal Component 2
Principal Component 1
Principal Component 2
beer whisky
Eigenvalues
Principal Component 1
Figure 10: Some examples of the factorial maps depicting morphological variation that can
be obtained with Momocs. The first two principal component axes are shown, (PC1 and PC2
are the x- and y-axis, respectively). The top figure displays the factorial map with no display
of the classes, a neighboring graph, shapes reconstructed from the factorial map using the
first two PC axes, and “rugs” along the axes; the bottom figure shows eigenvalues, confidence
ellipses for the two groups and another option for displaying the morphological space, as a
grid of bottles.
The outcome of this analysis shows that shapes of the whisky and beer bottles significantly
differ.
Hierarchical clustering
Momocs also includes a method to perform hierarchical clustering that hinges on dist and
hclust for calculation, and [Link] from the ape package for graphical output (see Par-
adis, Claude, and Strimmer 2004 and Paradis 2012). This can be achieved with the code
below (Figure 11):
R> clust(botF)
Call:
hclust(d = dist(botE@coe, method = method))
Other methods, such as linear discriminant analysis, etc. exemplified in Claude (2013) will be
integrated in further versions of Momocs.
gie
wh
whisky
oran
isk
whis
yg
llan
oban
lenm
len
tamdhu
whisky jb
ky a
ga
ffe
dro
be
k
ky g
ou
a
b
rie
whisky
ee
ym
er
mru
ch
na
sk
f
rc
ra
an
whis
ce
ch
isk
be
nz
y
m
ke
i
er
ro
rn
is
de
ur
wh
k
ka
na
ing t er
lin
ild
alk
ne
be
fis
yw
er
ew
r
be he k i
be
er r is n
hn
bee can wh ky jo e
r ho ey is rous
ega
rdee w h
a m ousg
n ky f
beer we whis
stmalle hma
beer bra
beer pecheresse whisky bushmills
iler beer sie
beer jup rraneva
da
bee
ro r gri
r tau wh m b
bee s isk erge
n
tine be y ja
allan el er ckd
a
yb uv gu nie
w
s k r d ine ls
hi
i
e
wh e ss
be
sk
pp
be
be
y
er
tra
whis
yo
whisky
tr u
er
la
tan
ero
ic
re
er
en
hi
whisky chivas
chy
gle
mark
be
ky h
otr
almo
v
us
foo
ma
ldp
de
redbrea
ighla
t
makers
ky d
y
yo
er
be
isk
ndp
whis
wh
st
ark
whisky
Figure 11: An example of the hierarchical clustering and the graphical output that can be
obtained with Momocs on the matrix of coefficients calculated on the bot dataset.
Figure 12: Some examples of the visualization of the deformation grids obtained using thin
plate splines in Momocs. From top to bottom: a simple deformation grid; isodeformation
lines; and a vector field that all depict the bindings required to pass from the average shapes
for beer and whisky.
data philosophy, as encouraged by the R Core Team and the many package developers, and
hope that Momocs will become a hub for such activity.
Acknowledgments
We thank the reviewers for all of their work and valuable comments made during the review
process. We warmly thank Allan Bailur for his invaluable help with the presentation in
English, along with Anna Seastrand on earlier versions of this manuscript. ANR-BDIV-07-008
supported VB and CG for this study; ANR-11-CEPL-002 and ANR-11-BCV-008 supported
JC for this study.
Journal of Statistical Software 21
References
Adams DC, Rohlf FJ, Slice DE (2004). “Geometric Morphometrics: Ten Years of Progress
Following the ‘Revolution’.” Italian Journal of Zoology, 71(1), 5–16.
Bonhomme V (2012). “A Graphical Introduction to Momocs and Outline Analysis Using R.”
Version 2012-10-17, URL [Link]
Bookstein FL (1991). Morphometric Tools for Landmark Data: Geometry and Biology. Cam-
bridge University Press.
Bowman A (2009). “Review of ‘Morphometrics with R’.” Journal of Statistical Software, Book
Reviews, 31(1), 1–2. Book author: Julien Claude, URL [Link]
b01/.
Courtiol A, Ferdy JB, Godelle B, Raymond M, Claude J (2010). “Height and Body Mass
Influence on Human Body Outlines: a Quantitative Approach Using an Elliptic Fourier
Analysis.” American Journal of Physical Anthropology, 142(1), 22–29.
Crampton JS (1995). “Elliptical Fourier Shape Analysis of Fossil Bivalves: Some Practical
Considerations.” Lethaia: An International Journal of Palaeontology and Stratigraphy,
28(2), 179–186.
Dray S, Dufour AB (2007). “The ade4 Package: Implementing the Duality Diagram for
Ecologists.” Journal of Statistical Software, 22(4), 1–20. URL [Link]
org/v22/i04/.
Dryden I (2012). shapes: Statistical Shape Analysis. R package version 1.1-6, URL http:
//[Link]/package=shapes.
Friess M, Baylac M (2003). “Exploring Artificial Cranial Deformation Using Elliptic Fourier
Analysis of Procrustes Aligned Outlines.” American Journal of Physical Anthropology,
122(1), 11–22.
Iwata H, Nesumi H, Ninomiya S, Takano Y, Ukai Y (2002). “Diallel Analysis of Leaf Shape
Variations of Citrus Varieties Based on Elliptic Fourier Descriptors.” Breeding Science,
52(2), 89–94.
Kendall D (1989). “A Survey of the Statistical Theory of Shape.” Statistical Science, 4(2),
81–120.
Kuhl FP, Giardina CR (1982). “Elliptic Fourier Features of a Closed Contour.” Computer
Graphics and Image Processing, 18(3), 236–258.
Macleod N (1999). “Generalizing and Extending the Eigenshape Method of Shape Space
Visualization and Analysis.” Paleobiology, 25(1), 107–138.
Miller HJ, Wentz EA (2003). “Representation and Spatial Analysis in Geographic Information
Systems.” The Annals of the Association of American Geographers, 93(3), 574–594.
Moellering H, Rayner JN (1981). “The Harmonic Analysis of Spatial Shapes Using Dual Axis
Fourier Shape Analysis (DAFSA).” Geographical Analysis, 13(1), 64–77.
Paradis E (2012). Analysis of Phylogenetics and Evolution with R. 2nd edition. Springer-
Verlag, New York.
R Core Team (2013). R: A Language and Environment for Statistical Computing. R Founda-
tion for Statistical Computing, Vienna, Austria. URL [Link]
Richtsmeier JT, Burke Deleon V, Lele SR (2002). “The Promise of Geometric Morphometrics.”
American Journal of Physical Anthropology, 119(S35), 63–91.
Rohlf F, Archie J (1984). “A Comparison of Fourier Methods for the Description of Wing
Shape in Mosquitoes (Diptera: Culicidae).” Systematic Biology, 33(3), 302–317.
Rohlf FJ (1990). “An Overview of Image Processing and Analysis Techniques for Morpho-
metrics.” In Proceedings of the Michigan Morphometrics Workshop, Special Publication
Number 2, pp. 47–60. University of Michigan Museum of Zoology, Ann Arbor.
Rohlf FJ, Slice D (1990). “Extensions of the Procrustes Method for the Optimal Superimpo-
sition of Landmarks.” Systematic Zoology, 39(1), 40–59.
Wentz EA (2000). “A Shape Definition for Geographic Applications Based on Edge, Elonga-
tion, and Perforation.” Geographical Analysis, 32(2), 95–112.
Zahn CT, Roskies RZ (1972). “Fourier Descriptors for Plane Closed Curves.” IEEE Transac-
tions on Computers, 21(3), 269–281.
Affiliation:
Vincent Bonhomme
Department of Ecology
French Institute of Pondicherry
600 001 Pondicherry, India
E-mail: [Link]@[Link]
Current affiliation:
Centre de Bio-Archéologie et d’Ecologie
UMR 5059 CBAE
34 000 Montpellier, France
Sandrine Picq
Centre de Bio-Archéologie et d’Ecologie
UMR 5059 CBAE
34 000 Montpellier, France
Current affiliation:
Université du Québec en Abitibi-Témiscamingue
Rouyn-Noranda J9X 5E4, Québec, Canada
24 Momocs: Outline Analysis Using R
Julien Claude
Institut des Sciences de l’Évolution
Université de Montpellier II
34 095 Montpellier, France
Cédric Gaucherel
Department of Ecology
French Institute of Pondicherry
600 001 Pondicherry, India