open-discussion
open-discussion > RE: Choosing ROIs using matlab and niii files
Sep 26, 2014 09:09 AM | Ged Ridgway
RE: Choosing ROIs using matlab and niii files
Hi Nir,
I'm assuming you want to get a binary mask for one or more ROIs, right?
The first step is to look up the regions that you want and get their numbers; you can do that interactively using tkmedit or freeview, or you can find the region names here:
https://surfer.nmr.mgh.harvard.edu/fswik...
E.g. if you want the left and right caudate the numbers are 11 and 50.
Consider what space you need the regions in: native (as acquired) or FreeSurfer's "conformed" (256 cubed, 1mm cubic voxels) space. For example, if you plan to do any further work (e.g. coregistration of a functional image, etc.) using FreeSurfer's T1.mgz, then you can work with the FreeSurfer space aparc+aseg, but if your other work is based on the original pre-FreeSurfer image, then you'll want to convert the aparc+aseg to native (rawavg) space. If you need native, see the mri_label2vol command here:
https://surfer.nmr.mgh.harvard.edu/fswik...
You can use FreeSurfer's matlab function MRIread on an mgh/mgz file directly (without converting to NIfTI) or you can use it on a converted nii.gz. Then you can get a binary mask using the matlab function ismember together with a vector of your region numbers (e.g. 11 and 50 for the caudate, as noted above), i.e.
img = MRIread('aparc+aseg.mgh');
msk = ismember(img.vol, [11 50]);
Finally, you can write out the binary mask using MRIwrite, e.g.
img.vol = msk;
MRIwrite(img, 'caudates.nii');
I hope that's useful, but if you want further help, you will probably have more success on the FreeSurfer mailing list:
https://surfer.nmr.mgh.harvard.edu/fswik...
All the best,
Ged
I'm assuming you want to get a binary mask for one or more ROIs, right?
The first step is to look up the regions that you want and get their numbers; you can do that interactively using tkmedit or freeview, or you can find the region names here:
https://surfer.nmr.mgh.harvard.edu/fswik...
E.g. if you want the left and right caudate the numbers are 11 and 50.
Consider what space you need the regions in: native (as acquired) or FreeSurfer's "conformed" (256 cubed, 1mm cubic voxels) space. For example, if you plan to do any further work (e.g. coregistration of a functional image, etc.) using FreeSurfer's T1.mgz, then you can work with the FreeSurfer space aparc+aseg, but if your other work is based on the original pre-FreeSurfer image, then you'll want to convert the aparc+aseg to native (rawavg) space. If you need native, see the mri_label2vol command here:
https://surfer.nmr.mgh.harvard.edu/fswik...
You can use FreeSurfer's matlab function MRIread on an mgh/mgz file directly (without converting to NIfTI) or you can use it on a converted nii.gz. Then you can get a binary mask using the matlab function ismember together with a vector of your region numbers (e.g. 11 and 50 for the caudate, as noted above), i.e.
img = MRIread('aparc+aseg.mgh');
msk = ismember(img.vol, [11 50]);
Finally, you can write out the binary mask using MRIwrite, e.g.
img.vol = msk;
MRIwrite(img, 'caudates.nii');
I hope that's useful, but if you want further help, you will probably have more success on the FreeSurfer mailing list:
https://surfer.nmr.mgh.harvard.edu/fswik...
All the best,
Ged
Threaded View
| Title | Author | Date |
|---|---|---|
| Nir Schwartz | Sep 22, 2014 | |
| Ged Ridgway | Sep 26, 2014 | |
