Hi Gabriel,

Attached is a script that probably does what you need. Just make it executable and call it without arguments to get usage information. The label indices you can get from the aseg.stats file or from FreeSurferColorLUT.txt.

The surfaces will be saved in a subdirectory called "ascii" inside each subject's directory, and have extension .srf. They are internally the same as the .asc surfaces, just with a different extension.

Note that the idea of the script is to generate surfaces for visualization purposes only. If you'd like to do statistical analysis (e.g., compare shapes between patients and controls), these surfaces may not be appropriate.

Hope it helps!

All the best,

Anderson


On 07/05/12 12:15, Gabriel Gonzalez Escamilla wrote:
Hello all FS users and experts,

I'm wanting to get the sub cortical segmentation as ASCII files, so I'm trying convert the aseg.mgz into a surface file, to finally get an ASCII file,
For this I'm using the next commands:

First: mri_convert -rl rawavg.mgz -rt nearest aseg.mgz aseg2raw.nii
To preserve  the aseg volume in native space

Second: mri_vol2surf --mov aseg2raw.nii --regheader mysubject --hemi lh --o ./lg.aseg2raw.mgh

And last: mris_convert lh.aseg2raw.mgh lh.aseg2raw.asc

I'm Not sure if I should do this for the whole aseg or if should I try to separate the segmented structures first...

Many Thanks in advanced,
Gabriel


_______________________________________________
Freesurfer mailing list
Freesurfer@nmr.mgh.harvard.edu
https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer


The information in this e-mail is intended only for the person to whom it is
addressed. If you believe this e-mail was sent to you in error and the e-mail
contains patient information, please contact the Partners Compliance HelpLine at
http://www.partners.org/complianceline . If the e-mail was sent to you in error
but does not contain patient information, please contact the sender and properly
dispose of the e-mail.

#!/bin/bash

# Print usage if no argument is given
if [ -z "$1" ]; then
cat <<EOU
Generate surfaces for the subcortical structures
segmented with FreeSurfer.

Usage:
sub2srf -s <list of subjects> [-l <list of labels>] [-d]

Options:
-s <list> : Specify a list of subjects between quotes,
            e.g. -s "john bill mary mark" or a text file
            containing one subject per line.
-l <list> : Specify a list of labels between quotes,
            e.g. "10 11 14 52 253", or a text file
            containing one label per line, or ignore
            this option to convert all labels.
-d          Debug mode. Leave all temporary files.

Requirements:
FreeSurfer must have been configured and the variables
FREESURFER_HOME and SUBJECTS_DIR must have been correctly set.

_____________________________________
Anderson M. Winkler
Institute of Living / Yale University
Jul/2009
EOU
exit
fi

# List of labels to be converted  if no list is specified
LABLIST="4 5 7 8 10 11 12 13 14 15 16 17 18 26 28 43 44 46 47 49 50 51 52 53 54 
58 60 251 252 253 254 255"

# Check and accept arguments
SBJLIST=""
DEBUG=N
while getopts 's:l:d' OPTION
do
  case ${OPTION} in
    s) SBJLIST=$( [[ -f ${OPTARG} ]] && cat ${OPTARG} || echo "${OPTARG}" ) ;;
    l) LABLIST=$( [[ -f ${OPTARG} ]] && cat ${OPTARG} || echo "${OPTARG}" ) ;;
    d) DEBUG=Y ;;
  esac
done

# Prepare a random string to save temporary files
RND0=$(head -n 1 /dev/random | md5sum)
RNDSTR=${RND0:0:12}

# Define a function for Ctrl+C as soon as the RNDSTR is defined
trap bashtrap INT
bashtrap()
{
  break ; break
  [[ "${s}" != "" ]] && rm -rf ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR} # try to 
delete temp files
  exit 1
}

# For each subject
for s in ${SBJLIST} ; do

  # Create directories for temp files and results
  mkdir -p ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}
  mkdir -p ${SUBJECTS_DIR}/${s}/ascii

  # For each label
  for lab in ${LABLIST} ; do

    # Label string
    lab0=$(printf %03d ${lab})

    # Pre-tessellate
    echo "==> Pre-tessellating: ${s}, ${lab0}"
    ${FREESURFER_HOME}/bin/mri_pretess \
           ${SUBJECTS_DIR}/${s}/mri/aseg.mgz ${lab} \
           ${SUBJECTS_DIR}/${s}/mri/norm.mgz \
           ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0}_filled.mgz

    # Tessellate
    echo "==> Tessellating: ${s}, ${lab0}"
    ${FREESURFER_HOME}/bin/mri_tessellate \
           ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0}_filled.mgz \
           ${lab} ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0}_notsmooth

    # Smooth
    echo "==> Smoothing: ${s}, ${lab0}"
    ${FREESURFER_HOME}/bin/mris_smooth -nw \
           ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0}_notsmooth \
           ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0}

    # Convert to ASCII
    echo "==> Converting to ASCII: ${s}, ${lab0}"
    ${FREESURFER_HOME}/bin/mris_convert \
           ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0} \
           ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0}.asc
    mv ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0}.asc \
       ${SUBJECTS_DIR}/${s}/ascii/aseg_${lab0}.srf
  done

  # Get rid of temp files
  if [ "${DEBUG}" == "Y" ] ; then
    echo "==> Temporary files for ${s} saved at:"
    echo "${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}"
  else
    echo "==> Removing temporary files for ${s}"
    rm -rf ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}
  fi
  echo "==> Done: ${s}"
done
exit 0
_______________________________________________
Freesurfer mailing list
Freesurfer@nmr.mgh.harvard.edu
https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer


The information in this e-mail is intended only for the person to whom it is
addressed. If you believe this e-mail was sent to you in error and the e-mail
contains patient information, please contact the Partners Compliance HelpLine at
http://www.partners.org/complianceline . If the e-mail was sent to you in error
but does not contain patient information, please contact the sender and properly
dispose of the e-mail.

Reply via email to