Skip to content
witthoft edited this page Nov 2, 2016 · 53 revisions

rxAlign is a script that calls the mrRx tool to align inplane anatomicals to a volume anatomy.

Table of Contents

Before you begin

Check your inplanes and functionals have the same prescription.

The assumption is that you have collected images of anatomical slices that have the same prescription as your functional data. The transformation which aligns the anatomical slices to the volume anatomy can then be applied to the functional images. Therefore, before doing the alignment it is always worth verifying that your inplanes and your functional images have the same prescription. This can be done by looking at the mean maps for each run on the inplanes in mrVista.

rxAlign GUI

This guide assumes that the current directory in matlab is the session directory (the one containing the mrSession.mat file). To start rxAlign, type rxAlign at the matlab command prompt, or select *Edit | Edit/View Alignment* from a mrVista window..

      rxALign

Four figures will open on screen.

The top figure title mrRx, allows you to search for and save a transform which brings your inplanes into alignment with the volume. The bottom left figure, labeled mrRx prescription on volume, shows a slice prescription (red lines) on your volume anatomy. Adjusting the sliders in the mrRx window moves the slice prescription around. The bottom center figure (labeled mrRx Prescribed Slice) shows what an in plane given the slice prescription would look like. The inplane chosen corresponds to the yellow line in the mRx Prescription window. The bottom right window labeled mrRx reference slice, shows the corresponding inplane from your data.

In brief, you use the manual controls in the mrRx window to adjust the prescription until the mrRx Prescribed and Reference slices look as similar as possible. Then an automatic alignment algorithm is employed to fine tune the alignment. Once an acceptable alignment is achieved it is saved for use by mrVista.

mrRx controls

The left-most panel contains a list of default and stored alignments. The other 4 panels have controls for manually aligning the inplanes to the volumes. These are fairly easily understood by adjusting them and watching the affect on the slices in the prescription on volume window and the interpolated slice. A brief summary:

the rxSlice slider changes which slice is currently being interpolated and compared. the current slice is highlighted in yellow in the rxPrescription on volume window.

Rot/trans step adjusts how far the interpolated inplane will move when adjusting the rotation and translation sliders one step.

The rotation and translation sliders do what they say.

Checking or unchecking the boxes at right will flip the prescription in that plane (axial, sagittal, coronal).

manual alignment

using a screen save

At Lucas, there was a screen save function that would save a dicom image with the prescription on it. This image could then be put in

sessionname/Raw/Anatomy/SS/

And opened from the menubar at

      Window>Open Screen Save Window

images/rxAlign/750px-RxAlign_Screen_Save.png

....replace this with a better image....

Although this option may not be available to you, it is still very useful to obtain a screenshot of the functional slice prescription on the scout when you are at the scanner (usually available using print screen on the scanner keyboard). Often the most time consuming step is getting the inplanes roughly aligned with the anatomy and having an image which shows where they were on the scout can greatly speed up this process.

saving in progress alignments

When you’re satisfied with the manual alignment, press the ‘Store’ button, on the lower left-hand side of the mrRx window, to store the current settings. You may also want to select the menu option ‘File’ | ‘Save…’ | ‘mrRx settings’ to save out these settings to file. You can always return to those settings by highlighting them in the settings list and then clicking the restore button. You can also give them a name by highlighting them and using the rename button. It is generally a good idea to always store your manual alignment before trying one of the automatic alignment options. Sometimes when the manual alignment is insufficiently close the output of the automatic alignment will be worse than what you started with. In that case it is convenient to be able to quickly return to the previous state.

Algorithmic Alignment

The automatic alignment algorithms can be invoked by using the pull-down menu under Alignment. If you have put some effort into the manual alignment it is worth saving it before this step as the alignment can sometimes end up with a worse looking alignment than the one it began with. This is more likely when the alignment between the inplanes and interpolated slices is not similar already. When this happens it saves time to be able to return previous work.

Nestares Alignment

From the menu select Alignment>>Fine>>Nestares Code. The Nestares code refers to the alignment method developed by Oscar Nestares and David Heeger, described in this paper:

Nestares O, Heeger DJ, 2000 Robust multiresolution alignment of MRI brain volumes. Magn Reson Med. 43(5):705-15.

Mutual Information

The Mutual-Information alignment refers to a mutual-information based metric which uses the SPM co-registration tools (see the spm_coreg function in SPM2)

Point based alignment

Point alignment is an option, though often not necessary. Point alignment works best when you are pretty close to a good alignment. It should always be your last step.

It is important to pick clear and reproducible points whenever you are using this feature. T-junctions in the gray matter are usually the most point-like structure in the brain.

To add points go to the pull down menu and select Edit | Points | Add Points. The the mrRx Reference Slice figure will turn yellow. Select a point on the reference slice for which you can find the corresponding point in the prescribed slice.

Choosing points can be easier and more accurate when you zoom in on a brain section.

It is also useful to go through and put 3-4 points for every few even slices in the brain, making sure to cover lateral, medial, ventral and dorsal parts of the brain evenly. You can then repeat this for the odd slices.

Select the corresponding point on the prescribed slice. Repeat the process for as many points as you want to add. Press the right mouse button to stop adding points.

Switch to another slice, and add more corresponding points (you can do a series of even slices followed by a series of odd slices). It’s a good idea to select points in early, middle, and late slices in the inplanes, to avoid have the alignment be close for one area, but get progressively worse away from that region.

It is a good idea to store the current prescription settings, using the ‘Store’ button in the mrRx window, before computing the from-points alignment.

Select Alignment | Fine | From Selected Points. A new alignment will be created, and stored under the name Point Alignment. Feedback will be provided on the amount of error between each point and the computed ideal point. If one point has a much higher error than the other points, it was likely poorly chosen (the points on the reference and prescribed slices don’t really correspond). You can delete the points using ‘Edit’ | ‘Points’ | ‘Delete Points’ <Ctrl-D>. A good alignment has an error of less than 1 for all points.

Check Alignment

mrRx compare Interpolation/Reference

 When the same features are visible in each slice, select the menu option ‘Window’ | ‘Open Rx/Ref Comparison Window’. A new figure will open up to the lower left:

Comparison methods (mrRx Compare Interp/Ref

Overlay (red/blue): Here it is helpful to adjust the amount of red and blue contributed from each image by adjusting the Rx alpha and Ref alpha sliders until you can make out the outlines of both brains.

  • Thresholded Overlay : This is one of my favorites as the different images seem easier to see than in the default method of red/blue overlay. I adjust the Ref alpha downwards (so that the red heat map starts to reveal more and more brain underneath. I dial the alpha down until I just start to see outlines of sulci and ventricles, and then all I have to do is try to match up the outlines. Checkerboard: The usefulness of this method relies you your finding a slice where the checkerboards split some kind of outline (e.g., a long sulcus), such that you can try to match up the trajectory of the line across the different images. You can also make the checkerboard checks larger by editing rxCompare case 3: compareImg = regMosaic(A, B, 10) (change the third number to a smaller number like 5.
  • Subtract: Before interpreting this map, make sure you have chosen in, in the mrRx Compare Interp/Ref window, Comparison Prefs-> Use mrAlign Intensity Correction, otherwise you will mostly be seeing intensity inhomogeneity regions, not regions of misalignment.
  • Correlation [R] values: If you have trained your eye well to know what a good alignment looks like (e.g., by trying many yourself and looking at many examples), you can safely ignore this number. There does not seem to be a value at which you can rest assured you have a good alignment, correlations vary from alignment to alignment, and the number may actually go down if you have a good brain alignment (e.g., if the skull misalignment then becomes large). Trust your eye, not this number. </p>

    This figure allows you to overlay the reference and prescribed slices. Three visualizations are possible: showing the prescibed slice in red and the reference slice in blue-green, such that high overlap appears gray; showing a color-coded image of the prescribed minus the reference slice; and showing a checkerboard of alternating tiles of prescribed and reference images. These can be selected with the popup at the bottom of the figure. In addition a correlation measure, and root-mean-squared error, are shown between to the two slices. Making the slices similar entails finding a local maximum for the correlation, and a local minimum for the error.

    You can toggle between two images with the toggle button at the lower right-hand corner of the comparison figure. In addition, there is a menu option on the Comparison Figure: Comparison Prefs | Compare all slices (separate GUI). A new window will open with the two volumes superimposed. You can set both volumes to a grayscale colormap using Ctrl-5; and toggle between the two quickly using Ctrl-T.

    Examine Mean Map on Volume in mrVista

    <

    7) </pre>

    If you are saving over a previous alignment, you will want to re-install the segmentation using the menu

    Gray &gt;&gt; Gray/White Segmentation &gt;&gt; Install or Reinstall Segmentation
    

    in the mrVista view. If you just want to save the alignment settings without saving it as the main alignment, select

    File &gt;&gt; Save... &gt;&gt; mrRx Settings
    

    This will create a file mrRxSettings.mat in the current directory, containing a list of all alignment settings. /group/vista/cgi-bin/wiki/index.php?title=RxAlign&action=edit&section=6" title="Edit section: User tips on achieving a good Inplane-&gt;Volume alignment" Toggling in the Rx/Ref Comparison Window is useful. The ideal would be to hit toggle, and not be able to distinguish when the toggling switches between the Rx image and the Ref image. In reality, this will never actually happen. But you can get close. For novice togglers, it might be helpful to change the number of times (line 16, nToggles), or the speed at which the toggling occurs (line 37, pause(0.15)) by editing rxToggle.m

    [edit] Alignment Settings

    After you open RxAlign, you will have a list of different settings in the top left corner (add examples here).

    In addition to storing alignments, anytime you use any fine or coarse alignments like Point Alignment or Mutual Information, this alignment will be stored in the settings. Make sure to erase any unnecessary settings by highlighting and deleting.
  • [edit] Initial coarse alignment

    This is likely the first thing you will do in adjusting your alignment. Open a saved screen shot of your prescription (if it exists). From the mrRx window, go to Window -> Open Screen Save Window

    • Try to match up your 'mrRx Prescription on Volume Window' to your screen shot.
    • HOWEVER, if you do not have a SS, try to do a coarse alignment by hand and check to make sure:
      • The hemispheres match up (i.e., the inplanes and volume anatomy are not incorrectly right/left flipped relative to eachother)
      • Slices are close in the anterior/posterior position, up/down position, and close in terms of the slice angle.
      • This step is usually not necessary if the initial default alignment is close enough. <picture of initial close coarse alignment>

    [edit] Automatic
    • Mutual information (References):
      • If you were able to use the SS for alignment or you were successful in coarse aligning the inplane and volume by hand, use Alignment -> Fine -> Using Mutual Information.
        • Whenever you are using Alignment -> Fine, you are starting from the current mrRx settings instead of the initial default settings.
      • If the initial default alignment was acceptable and you didn't do any coarse hand alignment, use Alignment ->Coarse -> mrAlignMI
    • Nestares:

    [edit] Fine manual alignment

     Result of automatic alignment. These images are misaligned but it is hard to tell
    

    (https://github.com/vistalab/vistasoft/wiki/images/400px-NesatresAlignmentWithROI.jpg

    The ROI here is the union of all visual field maps defined in this subject. Loading the ROI makes it obvious that the automatic alignment did not do a good job

    After fine manual correction, the alignment is much better. You should check other slices to make sure that the alignment is good everywhere, and not just this slice.</div></div></div> </li></ul> </li>

  • You can make manual adjustments to improve alignment in the Rx/Ref comparison window
  • Check the alignment in the region or ROI you care most about
  • </ul>

    Consider the alignment in the images on the right. The top image is the result of an automatic alignment. It looks OK by eye.

    When you load an ROI, however, you can see the error. The error is especially clear around the cortex/cerebellum boundary. After hand-editing, the alignment is much better.


    Misalignment could have caused a single blob of activation near the POS to fall on the sulcus and "break up" into three pieces on the mesh</div></div></div>

      • Often the alignment is difficult to get to be equally good throughout all slices. A work-around is to go for the best alignment possible near the region you're interested in, and just keep notes on how bad the rest of the regions are. For example, if your project is interested in the fusiform gyrus, you should focus on aligning the central slices in that region instead of the most anterior or posterior end. However, what we've noticed is that if the alignment is really good, it's good over the entire range of the prescription.
      • In mrRx: File -> Load -> mrVista ROI: Lets you load a mrVista ROI which will be shown in the Rx/Ref comparison window. This should be an ROI of interest where you really need the alignment to be good. You can specifically go for the ROIs that show up as single blobs on the Inplane/Volume view, but that straddle a sulcus and break up into small pieces when shown on the mesh. A misalignment could cause a blob of activation that should be on a gyrus to shift over to a sulcus and artifically "break up" on the inflated cortical surface representation, as may be happening around the parietal-occipital fissure in the example image.
      • In order to see the ROI on the in the Rx/Ref comparison window, even if you toggle (usually they disappear on toggling), add the following code to rxToggle.m (written by JW)
    &amp;lt&#59;h3&amp;gt&#59;&amp;lt&#59;span class&amp;&#35;61&#59;&amp;quot&#59;editsection&amp;quot&#59;&amp;gt&#59;&amp;&#35;91&#59;&amp;lt&#59;a href&amp;&#35;61&#59;&amp;quot&#59;/group/vista/cgi&amp;&#35;45&#59;bin/wiki/index.php?title&amp;&#35;61&#59;RxAlign&amp;amp&#59;amp&amp;&#35;59&#59;action&amp;&#35;61&#59;edit&amp;amp&#59;amp&amp;&#35;59&#59;section&amp;&#35;61&#59;2&amp;quot&#59; title&amp;&#35;61&#59;&amp;quot&#59;Edit section&amp;&#35;58&#59; Background about mrRx&amp;quot&#59;&amp;gt&#59;edit&amp;lt&#59;/a&amp;gt&#59;&amp;&#35;93&#59;&amp;lt&#59;/span&amp;gt&#59; &amp;lt&#59;span class&amp;&#35;61&#59;&amp;quot&#59;mw&amp;&#35;45&#59;headline&amp;quot&#59; id&amp;&#35;61&#59;&amp;quot&#59;Background_about_mrRx&amp;quot&#59;&amp;gt&#59; Background about mrRx &amp;lt&#59;/span&amp;gt&#59;&amp;lt&#59;/h3&amp;gt&#59;
    &amp;lt&#59;p&amp;gt&#59;&amp;lt&#59;a href&amp;&#35;61&#59;&amp;quot&#59;/group/vista/cgi&amp;&#35;45&#59;bin/wiki/index.php/MrRx&amp;quot&#59; title&amp;&#35;61&#59;&amp;quot&#59;MrRx&amp;quot&#59;&amp;gt&#59;mrRx&amp;lt&#59;/a&amp;gt&#59; (for “mister prescribe”) is a Matlab tool for applying a slice prescription onto an anatomical volume. This slice prescription can be described mathematically as a &amp;lt&#59;a href&amp;&#35;61&#59;&amp;quot&#59;http&amp;&#35;58&#59;//en.wikipedia.org/wiki/Affine_transformation&amp;quot&#59; class&amp;&#35;61&#59;&amp;quot&#59;external text&amp;quot&#59; rel&amp;&#35;61&#59;&amp;quot&#59;nofollow&amp;quot&#59;&amp;gt&#59;4x4 affine transformation matrix&amp;lt&#59;/a&amp;gt&#59;. This matrix maps between coordinates in the original volume matrix, and a new coordinate space, which we call the &amp;quot&#59;prescription&amp;quot&#59;.
    &amp;lt&#59;/p&amp;gt&#59;&amp;lt&#59;p&amp;gt&#59;In general, this tool doesn&amp;&#35;39&#59;t require a second volume to make a prescription&amp;&#35;58&#59; you could test a prescription before going to the scanner, for instance (details for things like this are on the main &amp;lt&#59;a href&amp;&#35;61&#59;&amp;quot&#59;/group/vista/cgi&amp;&#35;45&#59;bin/wiki/index.php/MrRx&amp;quot&#59; title&amp;&#35;61&#59;&amp;quot&#59;MrRx&amp;quot&#59;&amp;gt&#59;mrRx&amp;lt&#59;/a&amp;gt&#59; page). However, when you call &amp;lt&#59;b&amp;gt&#59;rxAlign&amp;lt&#59;/b&amp;gt&#59;, you are specifically trying to make a prescription that matches the &amp;lt&#59;a href&amp;&#35;61&#59;&amp;quot&#59;/group/vista/cgi&amp;&#35;45&#59;bin/wiki/index.php/Inplane&amp;quot&#59; title&amp;&#35;61&#59;&amp;quot&#59;Inplane&amp;quot&#59;&amp;gt&#59;Inplane&amp;lt&#59;/a&amp;gt&#59; anatomies for your &amp;lt&#59;a href&amp;&#35;61&#59;&amp;quot&#59;/group/vista/cgi&amp;&#35;45&#59;bin/wiki/index.php/MrVista&amp;quot&#59; title&amp;&#35;61&#59;&amp;quot&#59;MrVista&amp;quot&#59;&amp;gt&#59;mrVista&amp;lt&#59;/a&amp;gt&#59; session.
    &amp;lt&#59;/p&amp;gt&#59;&amp;lt&#59;p&amp;gt&#59;rxAlign allows you to perform both automatic and manual alignment steps. You can save this 4x4 matrix in a number of formats, including the one used in the mrSESSION.alignment field. It allows you to alter translation and rotation settings (and, when necessary, flipping the volume along one axis or another)&amp;&#35;59&#59; shows the ‘interpolated’ inplane slices that result for these settings&amp;&#35;59&#59; and lets you compare those images to a reference image. In this case, the reference images are the inplane images collected during the scanning session. The goal is to make the interpolated inplanes as much like the collected inplanes as possible.
    &amp;lt&#59;/p&amp;gt&#59;
    &amp;lt&#59;h4&amp;gt&#59;&amp;lt&#59;span class&amp;&#35;61&#59;&amp;quot&#59;editsection&amp;quot&#59;&amp;gt&#59;&amp;&#35;91&#59;&amp;lt&#59;a href&amp;&#35;61&#59;&amp;quot&#59;/group/vista/cgi&amp;&#35;45&#59;bin/wiki/index.php?title&amp;&#35;61&#59;RxAlign&amp;amp&#59;amp&amp;&#35;59&#59;action&amp;&#35;61&#59;edit&amp;amp&#59;amp&amp;&#35;59&#59;section&amp;&#35;61&#59;3&amp;quot&#59; title&amp;&#35;61&#59;&amp;quot&#59;Edit section&amp;&#35;58&#59; The math part&amp;quot&#59;&amp;gt&#59;edit&amp;lt&#59;/a&amp;gt&#59;&amp;&#35;93&#59;&amp;lt&#59;/span&amp;gt&#59; &amp;lt&#59;span class&amp;&#35;61&#59;&amp;quot&#59;mw&amp;&#35;45&#59;headline&amp;quot&#59; id&amp;&#35;61&#59;&amp;quot&#59;The_math_part&amp;quot&#59;&amp;gt&#59; The math part &amp;lt&#59;/span&amp;gt&#59;&amp;lt&#59;/h4&amp;gt&#59;
    &amp;lt&#59;p&amp;gt&#59;Here&amp;&#35;39&#59;s a rough guide to how the mapping works&amp;&#35;58&#59; suppose you have a set of coordinates in your inplane anatomy, which you keep in a matrix you call &amp;lt&#59;b&amp;gt&#59;InplaneCoords&amp;lt&#59;/b&amp;gt&#59;. &amp;lt&#59;b&amp;gt&#59;InplaneCoords&amp;lt&#59;/b&amp;gt&#59; is a matrix with 3 rows and several (&amp;lt&#59;i&amp;gt&#59;N&amp;lt&#59;/i&amp;gt&#59;) columns&amp;&#35;58&#59; each column is the (row, column, slice) position of a voxel, respectively, in the inplane anatomy data matrix. What you want to know is, what is the set of coordinates in my reference volume anatomy which match these inplane coordinates? We can name this desired matrix &amp;lt&#59;b&amp;gt&#59;VolumeCoords&amp;lt&#59;/b&amp;gt&#59;. The mapping we want would be&amp;&#35;58&#59;
    &amp;lt&#59;/p&amp;gt&#59;
    &amp;lt&#59;pre&amp;gt&#59;&amp;lt&#59;b&amp;gt&#59;VolumeCoords&amp;lt&#59;/b&amp;gt&#59; &amp;&#35;61&#59; &amp;lt&#59;b&amp;gt&#59;Xform&amp;lt&#59;/b&amp;gt&#59; &amp;&#35;42&#59; &amp;&#35;91&#59;&amp;lt&#59;b&amp;gt&#59;InplaneCoords&amp;lt&#59;/b&amp;gt&#59;&amp;&#35;59&#59; &amp;lt&#59;b&amp;gt&#59;ones vector&amp;lt&#59;/b&amp;gt&#59;&amp;&#35;93&#59;
    

    In this case, Xform is the 4x4 affine matrix that you edit in mrRx, and the ones vector is just a vector of ones, one for each column in VolumeCoords. (We need this vector, to allow Xform to contain a set of translation terms, which don't depend on the particular coordinates in VolumeCoords.) InplaneCoords will be a 4 x N matrix, with each row representing the inplane coordinates for the cooresponding column in VolumeCoords.

    (One note about this: The mrSESSION.alignment matrix applies transformations in which the rotations are relative to the point (1,1,1), which is the upper left-hand corner of the first inplane slice. mrRx always rotates about the center of a volume; but again, this is accounted for when the alignment is saved.)

    [edit] Calling mrAlignMI alignment from mrRx

    You can run the same alignment steps as in mrAlignMI, by first starting rxAlign (step 1 below) and selecting the menu:

    Alignment &amp;amp&#59;gt&amp;&#35;59&#59;&amp;amp&#59;gt&amp;&#35;59&#59; Coarse &amp;amp&#59;gt&amp;&#35;59&#59;&amp;amp&#59;gt&amp;&#35;59&#59; Mutual Information (mrAlignMI)
    

    The code that performs this is rxFineMutualInf. This alignment tool gets an initial coarse alignment from the anatomy headers (if available; they're traditionally in Raw/Anatomy/Inplane), and optimizes using the spm mutual information code. If you want to use this code, but start from your current settings in mrRx rather than from the header information, select:

     Alignment &amp;amp&#59;gt&amp;&#35;59&#59;&amp;amp&#59;gt&amp;&#35;59&#59; Fine &amp;amp&#59;gt&amp;&#35;59&#59;&amp;amp&#59;gt&amp;&#35;59&#59; Mutual Information (mrAlignMI)
    

    These steps seem to produce high-quality alignments for many prescriptions. The one exception seems to be high-resolution sessions in which the prescription covers a very small part of the whole brain (e.g., part of one hemisphere). The code seems to do well for more common prescriptions using a surface coil, which only cover the posterior part of the brain (but a large amount of this cortex). Also note that by default, the code compensates for intensity gradients. This and other parameters can be adjusted by invoking the command (rxFineMutualInf) from the command line.

    he Control figure contains controls for setting a 4x4 affine transformation which can be applied to the volume anatomy (vAnatomy) to produce the inplane prescription. The Rx figure shows where on the vAnatomy the prescription lies. The Prescribed Slice figure shows an an interpolated slice from the vAnatomy, after the transformation has been applied. The Reference Slice figure shows the equivalent slice from the inplane anatomies.

    Clone this wiki locally