Wednesday, June 23, 2010

Registering Macaque Functional Images to an Atlas Anatomical image (mprage)

Most of this tutorial assumes that you are trying to do your analysis at the MGH Martinos center, stationed on a standard terminal running CentOS linux with all the FreeSurfer and FSL tools installed. If this is not correct, then you can get up to speed (even on a Windows system!) by just downloading the free VirtualBox from Sun Microsystems, and then download and install the FreeSurfer VirtualBox image from the MGH website. I *think* that the FreeSurfer tools already include FSL, but if not, just get FSL.

Background Assumptions about the state of your analysis:

1. You have already performed the preprocessing steps (i.e., slice-time correction, motion-correction, smoothing).
2. You have an UNSMOOTHED mean motion-corrected functional image that has been corrected for intensity inhomogeneity using something like mri_nu_correct.mni, with a parameter "--distance 10" to flatten the intensity profile of your mean EPI image. BTW, do this BEFORE skull stripping. It'll be much better. Also, AFTER skull stripping, you'll need to clean up your mask in FSLVIEW to put in brain matter that BET took out. I'll talk about this in another post.
3. You have a skull-stripped target anatomical (an atlas image perhaps) that you wish to register to and have resliced the anatomical to be the same size as your functional (generally 1mm iso).

If any of these assumptions are incorrect, then you can continue below.

Step 1, prepare the anatomical for registration

The anatomical must *look* like your functional. That's hard, since one is an MPRAGE image and the other is an EPI. But you can use Slicer's tool for this.

Start Slicer3 by typing "slicer3" in your linux box.

Play around with Slicer a little bit to at least learn how to load and view images and to save outputs.

now.
1. Load both images using File > Add Data
2. From the Module list, select Filtering and then "Histogram Matching
3. Select to make a new parameter set
4. Set: Input Volume == your anatomical ; Reference Volume == your EPI ; output == Create New Volume
5. It may help avoid confusion to immediately rename your output volume into something more memorable. Do this by selecting "rename" from the drop down list, while selecting Output Volume
6. Select to change the parameter "Number of Match Points" to about 1000 and hit apply. You should instantly see your nice anatomical image changed to having a intensity range similar to the EPI (darker sulci, flat contrast in the brain).
7. Select "Save" from the file menu. In Slicer's save menu, you can choose the file format you will save in. Make sure it's nifti, or gzip nifti (.nii or .nii.gz). Also, make sure to save it somewhere you'll know where to find it.

Step 2, Affine registration with FSL FLIRT

If you haven't already, read the FSL documentation on FLIRT. You're better off using the command line since many parameters are not available on the GUI.

Basically, here's the rough shape of the command you'll need to execute:

flirt -in meanEPI.nii -ref AnatomicalIm.nii -omat reg.mat -noresample -noresampblur -out meanEPI_reg.nii -v


parameters -in, -out, and -ref should be clear to you. Parameter -omat allows FLIRT to output the registration matrix to a file so that you can reuse it to register other functionals. Parameters -noresample and -noresampblur prevent blurring or resampling, which can reduce the resolution of your final output.

Once this is done, check the output (meanEPI_reg.nii) on the anatomical. You should be able to type:

fslview AnatomicalIm.nii meanEPI_reg.nii

The command starts up FSLVIEW, with the first image as the main image (background) and the next image as an overlay. If the two don't match, then you'll have to tweak FLIRT until it does it right.


Friday, June 18, 2010

Freesurfer on Macaque

There are hardly any good tutorials or references on how one could generate a freesurfer surface using freesurfer. There are many problems to following the standard human analysis that simply does not work well for the macaque brain. Below is a work-in-progress tutorial on how to generate freesurfer surfaces. This tutorial requires FSL and it's associated tools, as well as a working installation of freesurfer. The easiest way of getting all this is to download the VirtualBox image of FreeSurfer from the MGH website and voila!

Anyways, here goes the rough draft:

1. You should have a high-contrast, low noise MPRAGE of your monkey's brain. We typically use 0.35 mm isotropic voxel resolution, and scan between 9 to 12 times (each scan runs for 15 minutes) to generate a good mean image.

2. You should also aquire a T2 image while you acquire your MPRAGEs, as this will make skull extraction (a BIG deal with monkeys) much easier.

3. You must get your images in the orientation that FSL likes (nifti files, with very particular dimension ordering). You can use fslswapdim function for this. If you are converting dicoms from the scanner to nifti's using the mri_convert command (from the FreeSurfer distribution), make sure to pass the "--sphinx" argument to it. After this, run

fslswapdim inputvol.nii LR PA IS outputvol.nii

to correct the dimension directions as FSL likes it. Check with fsl_view.

4. If the images are properly aligned, you can now use the FSL Brain Extraction Tool (BET) to rip out the brain. Here, you can pass the T2 image for a much better skull stripping. Alternatively (haven't tried it, but in theory should work), you can generate a brain mask using the T2 by thresholding it, then filling the volume and cutting the brain out of the hi-res anatomical with this.

5. Once you have a nice clean skull-stripped brain, you'll have to correct for the non-uniform intensity across the image. This can be achieved easily by FreeSurfer's implementation of the MNI's N3 correction tool. Apply this using "mri_nu_correct", as follows:

mri_nu_correct --i skulStrippedBrain.nii --o skull_stripped_nu.nii --distance 24

The distance factor may need to be adjusted, depending on what type of coil you used, and how big your monkey is, etc. Increasing the distance factor makes the program look for lower-frequency modulations of the intensity, whereas smaller numbers (better for phased-array coils) look for higher spatial frequency modulations.

6. You can then use the FSL FAST tool to segment your volume into white, gray, and csf. Output the white matter image for FreeSurfer, and leave the rest alone.

7. Make a new subject directory in keeping with the FreeSurfer system by using mksubjdirs.

8. Now comes the fun part: FreeSurfer wants 1mm isotropic voxels, but your images are 0.35 mm iso, so if you ask FreeSurfer to work with them, it will have to downsample them to 1mm. That's no fun, so we play a trick.

8a. Start Matlab. Make sure to download the NIFTI toolbox from the NIFTI website. Using load_nii, load the image you want to prep, like this:

nii = load_nii('mynifti.nii');

Make sure the nifti file is not compress (not "niil.gz"). Then modify nii.hdr.pixeldim to reflect 1 mm voxel ( = [1 1 1 1 0 0 0], or just replace the 0.35 in the size vector by 1's).

nii.hdr.pixeldim = [1 1 1 1 0 0 0];

Now save the volume, keeping track of what you did:

save_nii(nii, 'newNiftiName.nii');

8b. Finally, convert to MGZ format, and make sure to tell it to CONFORM:

mri_convert -c invol_fake1mm.nii outvol_fake1mm.mgz

Now, do this for all your volumes. Then they'll be ready for FreeSurfer.

9. Fill in your white matter surface:
9a. load in tkmedit, like this:

tkmedit -f /directory/brain.mgz

9b. In tkmedit, make note of the VOXEL coordinates (bottom left of window, top row) for the corpus calosum and the pons.

9c. Go back to the command prompt and exceute the following on the white matter image:

mri_fill -CV 192 172 214 -PV 192 249 194 /subj/mri/wm/wm.mgz ../filled/filled.mgz

where CV and PV reflect the corpus callosum VOXEL coordinates, and PV that of the pons.

9d. Check the results in tkmedit. Should be cute.

10. Now, we follow the recon-all dev table, which uses mri_pretess as follows:

mri_pretess ../filled/filled.mgz 255 ../brain/nu.mgz ../filled-pretess255.mgz

Then,

mri_tessellate ../filled-pretess255.mgz 255 ../lh.orig.nofix

Then,

mris_extract_main_component ../lh.orig.nofix ../lh.orig.nofix

mris_smooth -nw ../lh.orig.nofix ../lh.smoothwm.nofix

mris_inflate -no-save-sulc ../lh.smoothwm.nofix ../lh.inflated.nofix

mris_sphere -q ../lh.inflated.nofix ../lh.qsphere.nofix

And now, repeat this for the righ hemisphere (rh.orig)

Thursday, October 21, 2004

How industrialization of education should proceed.

Where should industrialism end? Should every aspect of life be overwhelmed by a routine process to make everything, every object and service, available to everyone, or should certain things be excempt from industrialization? If something is exempt, it will undoubtedly lead to discrimination against a group of people. Are there conditions where this discrimination can be justified, or is this discrimination actually necessary? I will argue here that industrialization of educational institutes has diminished the net utility of education and the current dogma could only repair this process by enforcing discriminating laws that would select students based either on their socio-economic status or scholastic aptitude. I will show, however, that such a discrimination is unnecessary and the problem actually lies in the manner in which education has been industrialized.
In the Canadian society advanced education is more and more seen as a right instead of a priviledge. This is largely due to our approach to education--we feel education ought to be universal, because it enriches life in so many ways, enhancing one's employability and their overall appreciation of life. This view may then stand at odds to why we still have tuition fees for public secondary education. The idea is that we do so because taxes could not pay for everything, and thus a person wishing to receive an advanced education ought to pay for this adavancement themselves. So, here we are, with very low tuition fees that eventually act as small financial barriers to an advanced education. The tuition fees of today will be raised by tomorrow and the trend will continue, because government is less and less inclined to pay for such an endeavour.
If we feel that education is important and enriches our life, then why do we let our government raise the fee and make this inaccessible to a large group of us? Because the program is largely failing to deliver on it's implicit promises, and our value of university education is going down. It is analogous perhaps to our general view of governments--that they are becoming more and more corrupt and less and less atuned to our needs and aspirations. Advanced public education is becoming ineffective, and both government and the public is beginning to take notice. In the older days, a person with a B.A. was regarded highly in many ways. Today, a B.A. is often regarded less than a B.Sc., and even the B.Sc. is getting the boot and professional degrees that earn money have risen above all other acronyms. The reason is simple: a hundred years ago, and university graduate was actually an accomplished person. The student would know how to write beautifully and intellectually, how to read complicated material, and how to debate, argue, present, and overall extract the beauty of nature and arts. Today's students are being challenged less and less, partially due to public demands that education be more accessible, and partly due to the need for universities to "process" more students--thus the need to make all courses passable. In other words, rather than continuing the professor-student model of learning that one sees in martial-arts films, where the student must make great strides, demonstrate enduring patience and be demanding of oneself, our universities are using the business model, where education is a service to be sold and made profit on. This is where the exact problem lies.
It is absolutely essential that a profit be gained from education. If one does not profit from educating others, then it becomes a pointless enterprise. The problem lies in the belief that the profit ought to be earned financially and at the front-end by the universities. The profit ought to be earned by the general public and indirectly so. The general public, by paying the taxes that pay for education, is the purchaser of education. The general public then deserves to get what they are paying for. Many arms of the government would like to suggest that the university must produce employable products, but this is incorrect. The objective of public education is simply to enhance ones mental capabilities so that they can appreciate more, understand more, and resolve more of the issue and problems that are created in particular situations. This is the ultimate goal of education, not it's represented goal. Yes, it is best if public education produces employable products, but this is indeed accomplished by default if the university were to pursue it's ultimate goal directly. It is a re-direction to this ultimate goal that is needed to make the university process a viable one that results not only in employability, but more importantly, to enduring enhancement of the lives of individuals and thus society as a whole.
How could the university pursue this direct goal? It may be irrational to demand of this institution to return to it's earlier personality of the kung-fu master and apprentice. This approach, although potentially effective and partially necessary, is simply out of touch with our modern lifestyle and culture. We insist on our independence of thought and mind and we cannot give this up under any scheme. What we need instead is a new system of challenging education, challenging and constructive, whereby a student must push their own barriers of thought and understanding. Our students' energies are wasted at the moment studying for exams that test pure knowledge or fine details. Gameshows make us think that such detailed knowledge constitutes intelligence, although both intelligence testers and intuition tells us completely otherwise. How smart do you think someone is if they can name the capital of every province of an obscure nature? Are they smart, or have they got time on their hands?
And time is something our students do NOT have on their hands. The current scholastic approach is to teach our theories, dogmas, and knowledge. Yet all this dogma, theory and knowledge is available as texts and anyone with a trained mind can easily access them and incorporate them into their knoweldgebase. What we really need, then, is that trained mind, and this is the heart of our current problem.
The university must return to it's original goal by training minds to be better processors of information, not stores of it. A truly accomplished student is not one who can name the 50 species that live in a given patch of a forest or one who knows the exact pattern of a chemical reaction, but one who has learned to access and understand that information readily. The knoweledge is all there, ready to be read, but few readers are able to understand it now, and this is simply because the challenge of university is moved to treating the brains of our students with data and information rather than functions and properties. You do not buy a computer because it has an encyclopedia installed on it--you buy it because the processor and the software can do things for you. Education needs to make our brains do more for us, not hold more information for us. This enhancement of capability is therefore key.
There is evidence for the validity of this statement. The raw number of university degrees tends to be a poor indicator of GDP growth in a nation, and this is a surprising finding since almost everyone believes that with better education come better jobs. But recent analyses have finally correlated a specific aspect of educational outcome with GDP growth--skill development. When the average occurrence of a certain skill was compared to it's rate in a previous date ten years earlier, the rate of increase in the presence of the skills correlated highly with GDP growth. This implies that there is an aspect of education that is effective in driving economic success. Education must develop skills to drive economic advancement.
Here lies another misinterpretation. Governments (and the people who elect them) tend to think of skills as specific actions that you can conduct. But the ultimate goal of education is not to train you to enact certain actions--this is done through job-training. By developing your mind and enhancing its capability in processing complex information, universities will empower students with skills that are invisible, but most potent. To have students who can solve problems creatively, completely, and efficiently is not only an economic bliss but a wonderful and empowering individual acheivement. It may be debated whether current Arts programs are empowering students with enough of these mental skills, but there is strong evidence that programs such as Philosophy do output students who are more capable of logical reasoning and problem solving. Given the abstract nature of these skills, it implies that a philosophy student may be more capable than students of other fields to resolve a problem. Such a student, after studying basic chemistry or biology, may be more successful at resolving problems that have been encountered in a field, thus empowering the advancement of science and economy.
Mental skills are what is needed. The previous university culture that demanded greater obedience from students may have indirectly acheived some of that by demanding of the students to develop this mental prowess. But the time has come to bring back the goal of enhancing the human mind by developing mental skills, and this can only be achieved by drastic changes of the ways we teach university education. Rather than focussing on information storage, we ought to focus on information processing. The precious time that our students spend in the university ought to be spent changing their brains, not filling them. As such, the product of universities will indeed be of great utility to both the society and its economy. If this end is acheived, then the tax paying public will finally be getting the product it pays for, and the industrialization of this improved product will undoubtedly bring enduring benefits to the individuals and their society.