I'm interested in parsing aseg.mgz into separate binary mask files for each aseg label. Is this possible? The closest topic I found was located at the following URL:
http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/MapSegmentationsToFu nctionalSpace
2.0 Creating binary masks
The segmentation for a particular structure can be extracted to create a binary mask (i.e., a volume where the voxel value is 1 if it is in the structure and 0 otherwise). To make a binary mask of the left putamen, which has been assigned label 12 (see ${FREESURFER_HOME}/FreeSurferColorLUT.txt), use the following command:
avwmaths ./fbert.feat/reg/freesurfer/aparc+aseg.nii.gz \ -thr 12 -uthr 12 \ ./fbert.feat/reg/freesurfer/lh.putamen.nii.gz
I checked the following for additional help...but still need some help...
http://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferCommands
Many Thanks,
Jenifer
Hi Jenifer,
yes, you could do that for each label defined in the aseg.stats file (or the FreeSurferColorLUT.txt, but that will contain labels that don't exist in that volume).
what else are you trying to do that you need help with?
Bruce
On Mon, 14 May 2007, Juranek, Jenifer wrote:
I'm interested in parsing aseg.mgz into separate binary mask files for each aseg label. Is this possible? The closest topic I found was located at the following URL:
http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/MapSegmentationsToFu nctionalSpace
2.0 Creating binary masks
The segmentation for a particular structure can be extracted to create a binary mask (i.e., a volume where the voxel value is 1 if it is in the structure and 0 otherwise). To make a binary mask of the left putamen, which has been assigned label 12 (see ${FREESURFER_HOME}/FreeSurferColorLUT.txt), use the following command:
avwmaths ./fbert.feat/reg/freesurfer/aparc+aseg.nii.gz \ -thr 12 -uthr 12 \ ./fbert.feat/reg/freesurfer/lh.putamen.nii.gz
I checked the following for additional help...but still need some help...
http://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferCommands
Many Thanks,
Jenifer
You can also use mri_binarize (it takes any format as input). We don't have anything that will automatically generate a separate volume for each label.
Bruce Fischl wrote:
Hi Jenifer,
yes, you could do that for each label defined in the aseg.stats file (or the FreeSurferColorLUT.txt, but that will contain labels that don't exist in that volume).
what else are you trying to do that you need help with?
Bruce
On Mon, 14 May 2007, Juranek, Jenifer wrote:
I'm interested in parsing aseg.mgz into separate binary mask files for each aseg label. Is this possible? The closest topic I found was located at the following URL:
http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/MapSegmentationsToFu nctionalSpace
2.0 Creating binary masks
The segmentation for a particular structure can be extracted to create a binary mask (i.e., a volume where the voxel value is 1 if it is in the structure and 0 otherwise). To make a binary mask of the left putamen, which has been assigned label 12 (see ${FREESURFER_HOME}/FreeSurferColorLUT.txt), use the following command:
avwmaths ./fbert.feat/reg/freesurfer/aparc+aseg.nii.gz \ -thr 12 -uthr 12 \ ./fbert.feat/reg/freesurfer/lh.putamen.nii.gz
I checked the following for additional help...but still need some help...
http://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferCommands
Many Thanks,
Jenifer
Freesurfer mailing list Freesurfer@nmr.mgh.harvard.edu https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer
On May 14, 2007, at 6:28 PM, Juranek, Jenifer wrote:
I’m interested in parsing aseg.mgz into separate binary mask files for each aseg label. Is this possible? The closest topic I found was located at the following URL:
... I checked the following for additional help…but still need some help…
Here's a bash script that will automatically read through the aseg.stats file and run the "avwmaths" command for each segment. Put the stuff between the lines into a text file, call it something like aseg-breakout.sh, and run it with source aseg-breakout.sh subject- name edited-aseg.stats. I recommend you cut out only the lines you want from aseg-stats; if you run it on the whole thing it will generate about 685 output files at about 1 megabyte each on average which is a lot of data to fill your computer with. But hey, so is freesurfer.
Also, run it as is to make sure it finds the ones you want; then edit this file to remove the word "echo" and run it again to actually do it.
I haven't tested this live, but if the avwmaths command works as given, this should work too.
Maybe you need to do everything with a .nii.gz extension instead of mgz, I don't know. If you need to do that, just replace ".mgz" with ".nii.gz" everywhere in this script.
If you want to know how this works, here is an excellent and extremely detailed guide to bash scripts: http://tldp.org/LDP/abs/html/
----------------------cut here------------------------ #!/bin/bash # Usage: ./$0 subject-name aseg.stats # if $SUBJECTS_DIR is set properly, # it will know where to find the stats and the aparc+aseg.mgz # if you don't want to do all the segs in aseg.stats, # make a copy of the file with just the lines you want # and give that as input to this script
statsfile="${SUBJECTS_DIR}/${1}/stats/${2}" asegfile="${SUBJECTS_DIR}/${1}/mri/aparc+aseg.mgz" outputdir="${SUBJECTS_DIR}/${1}/mri/segmasks"
mkdir ${outputdir} # make a directory for all these output files to go into
outputextension=".mgz" # or whatever, .nii.gz would work too
while read theline; do # read one line from aseg.stat linearray=( ${theline} ) # parse the columns into an array if [[ ${linearray[0]:0:1} == '#' ]]; then : # do nothing, skip the lines where first character is # # because they are comments else threshold=${linearray[1]} # the intensity value of the segment segname=${linearray[4]} # the name of the segment echo avwmaths asegfile \ -thr ${threshold} -uthr ${threshold} \ ${outputdir}/${segname}${outputextension} fi done <${statsfile} # read input from the aseg.stats file or whatever is specified
----------------------cut here------------------------
-- -dave---------------------------------------------------------------- After all, it is not *that* inexpressible. -H.H. The Dalai Lama
freesurfer@nmr.mgh.harvard.edu