# Morphing

A common operation in Caret is surface flattening. However, when the surface is flattened, regions in the center of the flat surface (near the ventral tip of the central sulcus) are compressed and regions around the perimeter of the surface that were adjacent to the medial wall and the cuts, are expanded. These regions of compression and expansion result in surface distortion. Surface distortion also occurs when creating a spherical surface that is often used for surface-based registration.

A surface is made up of two components, nodes and topology. Nodes are the three dimensional XYZ-coordinates scattered about the surface. Topology connects the nodes with edges (links) to form triangles. The triangles in turn form a triangular mesh. As a result, and this is very important, one can move the nodes in XYZ space yet preserve the topology. In Caret, one always starts with a fiducial surface that has its nodes' coordinates modified to create inflated, spherical, and flat surfaces. When creating a flat surface, a new topology is created in which the medial wall region is removed and cuts are made that radiate from the perimeter of the medial wall. Without these cuts, reducing distortion in the flat surface would be severely restricted and parts of the surface might overlay or fold over itself.

To reduce surface distortion, caret employs an operation named surface morphing. Surface morphing compares the distorted surface with the fiducial surface that represents the true cortical anatomy. With the surfaces having the same topology, each triangle has a corresponding triangle in the other surface but with differing node coordinates. The shape of the triangles in the distorted surface are modified to better match the corresponding triangles in the fiducial surface resulting in reduced distortion.

Two different distortion measurements are available, areal and linear. Areal distortion is the ratio of the surface area of a triangle in one surface compared to the surface area of the corresponding triangle in the other surface. Linear distortion is the ratio of the linear distance from one node to a neighboring node in one surface compared to the linear distance between the nodes in the other surface. During the morphing process, these two distortions are calculated. Using these distortion measurements, forces are created for each node that adjust the nodes' coordinates in order to reduce the surface distortion.

To view surface distortion in Caret, select Surface Menu->Measurements->Generate Distortion. When this command is run, surface shape columns are created that contain the areal and linear distortion measurements. When distortion is selected for display using the Display Control Dialog, the distortion is showed as shades of gray. Regions of compression are shown in a dark gray to black color and regions of expansion are shown in a light gray to white color.

## Distortion Measurements

### Areal Distortion

AFi = Area of triangle i in the fiducial surface.

ASi = Area of triangle i in the other (distorted) surface.

$AD_i = \frac{log2(\frac{AS_i}{AF_i})}{log2(2.0)}$ = Distortion for triangle i.

NTj = Number of triangles used by node j.

TADjk = Areal distortion for node j's k'th triangle.

$NAD_j = \frac{\sum_{k=1}^{NT_j} TAD_{jk}}{NT_j}$ = Areal distortion for node j.

### Linear Distortion

Dij = Distance from node i to node j.

Ni = Number of neighbors for node i.

$NLD_i = \frac{\sum_{j=1}^{N_i} D_{ij}}{N_i}$ = Linear distortion for node i.

## Morphing Forces

### Linear Forces

LFS = Linear Force Strength

XYZi Coordinate of node i.

DDij = Distance from node i to node j in the distorted surface.

DFij = Distance from node i to node j in the fiducial (anatomically correct) surface.

$\overrightarrow{error} = XYZ_i- XYZ_j$ = vector formed by position of node j subtracted from node j.

$\overrightarrow{LF_{ij}} = \frac{((DF_{ij} - DD_{ij}) * LFS) * \overrightarrow{error}}{DD_{ij}}$ = Linear force components.

Ni = Number of neighbors of node i.

$\overrightarrow{LF_i} = \frac{\sum_{j=1}^{N_i} \overrightarrow{LF_{ij}}}{N_i}$= Linear force for node i.

### Angular Forces

AFS = Angular Force Strength

XYZi = Coordinate of node i.

Ni = Number of neighbors of node i.

$\overrightarrow{NORM_{ijk}}$ = Normal vector formed by nodes i, j, and k that make up a triangle.

DADijk = Angle formed by node i and its consecutive neighbors j and k in the distorted surface.

FADijk = Angle formed by node i and its consecutive neighbors j and k in the fiducial surface.

$\overrightarrow{dXYZ_{ij}} = XYZ_j - XYZ_i$ = vector formed by position of node i subtracted from node j.

$\overrightarrow{DIR_{ij}} = \overrightarrow{dXYZ_{ij}} \times \overrightarrow{NORM_{ijk}}$This creates a vector that is orthogonal to a plane formed by the vector from node i to node j and the triangle's normal vector. It indicates the direction that node i should be moved.

$\overrightarrow{AF_i} = \sum_{j=1}^{N_i} AFS * MAG_{ij} * \overrightarrow{DIR_{ij}}$

### Total Force

$\overrightarrow{TF_i} = \overrightarrow{AF_i} * StepSize + \overrightarrow{LF_i} * StepSize$

## Landmark Constrained Morphing

In landmark constrained morphing, nodes identified as landmarks are not morphed, that is, these node do not move. However, even though the node is not moved, its morphing forces are calculated and saved. If a node that is being morphed has a neighbor that is not being morphed the inverse force of the non-morphed neighbor is added to the node being morphed.

### Visualizing Forces

After running morphing, one can view the forces on a surface using the Surface Miscellaneous page of the Display Control Dialog. On this page are selections for displaying the angular, linear, and/or total forces.

### Running Surface Morphing

Select Surface->Morphing->Morph Flat Surface or Surface->Morphing->Morph Spherical Surface.

## Multi-Resolution Morphing

Since morphing can be a slow process, Caret run's multi-resolution morphing. During this process, the surface is subsampled (many nodes are removed) and a low resolution surface is created. This subsampled surface is then morphed. The results are then upsampled to a higher resolution surface that is then morphed. Using these multiple resolutions, typically five, substantially reduces the execution time yet yields a surface with significantly reduced distortion.

The multi-resolution morphing process runs in multiple cycles that follow morphing with smoothing. Morphing may create some crossovers and smoothing usually eliminates these crossovers.

### Running Multi-Resolution Morphing

Select Surface->Morphing->Multiresolution Morphing Flat Surface or Surface->Morphing->Multiresolution Spherical Surface.