-
Notifications
You must be signed in to change notification settings - Fork 141
mrAlign
rxAlign is a script that calls the mrRx tool to align inplane anatomicals to a volume anatomy.
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.
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.
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).
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.
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.
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.
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:
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 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.
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.
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.
<7) </pre>
If you are saving over a previous alignment, you will want to re-install the segmentation using the menu
Gray >> Gray/White Segmentation >> 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 >> Save... >> 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§ion=6" title="Edit section: User tips on achieving a good Inplane->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>
- 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
- 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.
- Nestares:
- This is another algorithmic option, but in our limited experience, MI seems better.
- More info and a reference are listed as step 7 in the walk-through
[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>
- See section above on slider, overlay, toggling, and zooming tips.
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)
&lt;h3&gt;&lt;span class&#61;&quot;editsection&quot;&gt;&#91;&lt;a href&#61;&quot;/group/vista/cgi&#45;bin/wiki/index.php?title&#61;RxAlign&amp;amp&#59;action&#61;edit&amp;amp&#59;section&#61;2&quot; title&#61;&quot;Edit section&#58; Background about mrRx&quot;&gt;edit&lt;/a&gt;&#93;&lt;/span&gt; &lt;span class&#61;&quot;mw&#45;headline&quot; id&#61;&quot;Background_about_mrRx&quot;&gt; Background about mrRx &lt;/span&gt;&lt;/h3&gt; &lt;p&gt;&lt;a href&#61;&quot;/group/vista/cgi&#45;bin/wiki/index.php/MrRx&quot; title&#61;&quot;MrRx&quot;&gt;mrRx&lt;/a&gt; (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 &lt;a href&#61;&quot;http&#58;//en.wikipedia.org/wiki/Affine_transformation&quot; class&#61;&quot;external text&quot; rel&#61;&quot;nofollow&quot;&gt;4x4 affine transformation matrix&lt;/a&gt;. This matrix maps between coordinates in the original volume matrix, and a new coordinate space, which we call the &quot;prescription&quot;. &lt;/p&gt;&lt;p&gt;In general, this tool doesn&#39;t require a second volume to make a prescription&#58; you could test a prescription before going to the scanner, for instance (details for things like this are on the main &lt;a href&#61;&quot;/group/vista/cgi&#45;bin/wiki/index.php/MrRx&quot; title&#61;&quot;MrRx&quot;&gt;mrRx&lt;/a&gt; page). However, when you call &lt;b&gt;rxAlign&lt;/b&gt;, you are specifically trying to make a prescription that matches the &lt;a href&#61;&quot;/group/vista/cgi&#45;bin/wiki/index.php/Inplane&quot; title&#61;&quot;Inplane&quot;&gt;Inplane&lt;/a&gt; anatomies for your &lt;a href&#61;&quot;/group/vista/cgi&#45;bin/wiki/index.php/MrVista&quot; title&#61;&quot;MrVista&quot;&gt;mrVista&lt;/a&gt; session. &lt;/p&gt;&lt;p&gt;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)&#59; shows the ‘interpolated’ inplane slices that result for these settings&#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. &lt;/p&gt; &lt;h4&gt;&lt;span class&#61;&quot;editsection&quot;&gt;&#91;&lt;a href&#61;&quot;/group/vista/cgi&#45;bin/wiki/index.php?title&#61;RxAlign&amp;amp&#59;action&#61;edit&amp;amp&#59;section&#61;3&quot; title&#61;&quot;Edit section&#58; The math part&quot;&gt;edit&lt;/a&gt;&#93;&lt;/span&gt; &lt;span class&#61;&quot;mw&#45;headline&quot; id&#61;&quot;The_math_part&quot;&gt; The math part &lt;/span&gt;&lt;/h4&gt; &lt;p&gt;Here&#39;s a rough guide to how the mapping works&#58; suppose you have a set of coordinates in your inplane anatomy, which you keep in a matrix you call &lt;b&gt;InplaneCoords&lt;/b&gt;. &lt;b&gt;InplaneCoords&lt;/b&gt; is a matrix with 3 rows and several (&lt;i&gt;N&lt;/i&gt;) columns&#58; 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 &lt;b&gt;VolumeCoords&lt;/b&gt;. The mapping we want would be&#58; &lt;/p&gt; &lt;pre&gt;&lt;b&gt;VolumeCoords&lt;/b&gt; &#61; &lt;b&gt;Xform&lt;/b&gt; &#42; &#91;&lt;b&gt;InplaneCoords&lt;/b&gt;&#59; &lt;b&gt;ones vector&lt;/b&gt;&#93;
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;gt&#59;&amp;gt&#59; Coarse &amp;gt&#59;&amp;gt&#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;gt&#59;&amp;gt&#59; Fine &amp;gt&#59;&amp;gt&#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.
- Vistasoft
- Getting Started
- mrVista Overview
- Anatomy
- Functional MRI
- mrVista
- Retinotopy tutorial
- Population RF methods also prf Model, prf_tutorial, prf tutorial
- Diffusion weighted MRI
- Visualization
- Tractography
- Tutorials
- Software overview