# Multilevel refinement

*Dynamo* computes the angles that produce the maximum correlation in a multilevel fashion. The project parameters `cone_range`, `cone_sampling`, `inplane_range` and `inplane_sampling` determine a *base level* that is scanned exhaustively.

## Contents

## Scanning procedure

### Definition of an angular grid

In Dynamo, an angular grid is defined by five parameters:

`‘cone_range’,`or`'cr'``’cone_sampling’,`or`'cs'``’inplane_range’,`or`'ir'``’inplane_sampling’,`or`'is'`- ’old _angles’

The first four are project parameters that can be chosen by the user and will be applied for the analysis of all particles during the project runtim. The last one, ‘old_angles’ is obviously different for each particle, and in runtime is read from the table (provided by the user or generated by Dynamo during the iteration procedure). The ‘cone_’ parameters define a set of orientations that will be sampled around a previously determined old orientation. Here we speak of orientations of the vertical axis of the template, not full unconstrained rotations. Allowing this axis to move inside a cone involves only two Euler angles (tdrot and tilt). ‘cone_range’, is the extent of this cone in degrees (360 being the full possible range of axis orientations). ’cone_sampling’ is the step inside this cone, also in degrees. The orientations are generated so as to provide an uniform coverage. The ‘inplane_’ parameters complete the set of scanned Euler triplets. After each of the axis reorentations defined by the ‘cone_’ parameters, the template will be rotated about the new orientation of its axis. This involves only the ‘narot’ angle. The project parameter ‘inplane_range’ defines the angular interval to be scanned around the old value of narot, and ‘inplane_sampling’ defines the interval. By convention, passing equal values to ‘inplane_range’ and ‘inplane_sampling’ generates a grid without ‘inplane’ rotations: only reorientations of the axis will be scanned.

### Base level scan

During the scanning procedure, *Dynamo* will start with a loop on the base level angles. In this loop scans a single angle by computing the full cross correlation matrix between the rotated template and the particle. Then, a shift limiting is applied onto the matrix, and the maximal cc inside the limited ccmatrix is computed. If this maximum is larger than the previously stored maximum for the full set of angles, this angle and the shifts where the cc maximum is located are set as best aligning parameter, and the cc is stored.

The set of angles scanned at this level is regularly distributed (in the space of rotations SO(3)) around the rotation stored for the particle in the previous iteration (which should be stored in the table)

## Refinement scan

When all the angles in the base level have been scanned, the optimal angles are considered and a new set of angles to scan is defined around these. The geometry of the new set is defined by the angular parameters of the previous level with this formula.

cone_range[l] = refine_factor*cone_sampling[l-1]; cone_sampling[l] = cone_sampling[l-1]/2;

The project parameter ‘refine’ defines how many times this process will be repeated for each particle. ‘refine_factor’ defines the range of the new set of angles. A value of 2, for instance, means that the range of the new grid should twice as large as the step of the old grid.

## Visualizing angular distributions

You can simulate the method of *Dynamo* to compute a multilevel refinement with the command ` dynamo_angles_multigrid`

g=dynamo_angles_multigrid(60,3,45,5,[0,45,0],3,2,0,0);

The output will be a cell array, each entry are the euler triplets at each level. The transition fro one level to the next is in this case generated around the center of the angular grid. Remember that in real applications the finer grid will be centered at the angle that yields the highest similarity.

The output can be shown with `dynamo_plotangles`. This function works for a matrix entry, so that in order to see the different levels, you'll need to iterate it:

for i=1:length(g); [x,h]=dynamo_plotangles(g{i}); h.MarkerFaceColor=rand(3,1); end

## Additional angular parameters

Some other parameters are available to define initial scanning orientations:

`cone_flip``inplane_flip`

When activated, they extend the basic grid generated by the basic parameters by flipping the original set. For instance,

g=dynamo_angles_multigrid(60,15,45,5,[0,0,0],0,1,1,0);figure;dynamo_plotangles(g);

would generate this scanning geometry: