Skip to content

ASHS segmentation

etiaum edited this page Mar 26, 2025 · 6 revisions

By Etienne Aumont

Automated Segmentation of Hippocampal Subfields (ASHS) is an automatic segmentation tool specialized in identifying low-contrast anatomical regions.
It is best used in a Linux OS

1. Installation

To run ASHS, you'll need 3 folders:

  • The ASHS software (ashs-fastashs_beta), found in my data03 directory. It can only be run from the home directory; copy it on your desktop.
  • An atlas with the right structure. One is in my data03 directory (ashsT1_atlas_upennpmc_wm_07172023). It's designed for T1 1mm images in older adults. There is another one for higher-resolution T2 images found on the ASHS website. Otherwise, it's fairly easy to build an atlas following the instructions found here
  • A well-structured directory with the images (in .nii) to be segmented and subdirectories for each image.

Tip: For the third one, I assembled the MRI in a directory and, while in this directory, created subdirectories with a loop like this one:

   For i in *.nii ; do mkdir ${i:0:14} ; done

Install ASHS by entering this line:

   export ASHS_ROOT=/home/etienne/Desktop/ashs-fastashs_beta

Note: It should be possible to add this line to your .bashrc, although it did not work for me. If it doesn't work, you'll need to re-enter the line every time

2. Running ASHS

To run ASHS, I recommend being in the directory where the MRI files are.
The command to launch ASHS looks like this:

   $ASHS_ROOT/bin/ashs_main.sh -P -I subject_ID -a /path/to/atlas/directory -g image_file -f image_file -w subject_directory

The second image, after the -f option, is for when you have a T2-weighted image. It will consider both sequences. When using T1 images, just enter the same image twice (under -f and -g).
The -P option is to run it with multiple cores using Parallel. It should be already functional on most lab computers. This option cuts the processing time by ~80%.
I recommend running ASHS on 1 subject to start with, verify if it works. You'll know it does when files are created in the subject_directory/final/.

When it works, you can run ASHS on several subjects with a for loop and the nohup function like this:

   nohup bash -c 'for i in NI93*.nii ; 
      #enough images for 1-2 days of work. I split the process between computers, each with its list of images to run
   do $ASHS_ROOT/bin/ashs_main.sh -P -I ${i:0:14} -a ashsT1_atlas_upennpmc_wm_07172023 -g $i -f $i -w ${i:0:14} ;
   done' > outputBroca.log &
      #this will store the log file in the current directory. Use different names for different computers.

3. ASHS output

You'll find the output in the subject's directory, containing ~1100 files. Only the files in final/ are of use to us. The rest of the files (most of all, bootstrap/ and multiatlas/, which account for ~80% of the directory's size) can be deleted if disk space is a constraint.
I recommend moving each image inside of the output directory once the segmentation is complete.

ASHS gives 2 types of outputs: .txt files containing the volume of each region and .nii.gz files containing the region masks. Left and right hemispheres are separated.

The ASHS segmentation created using 3 different methods:

  1. _lfseg_heur: less accurate, do not use
  2. _lfseg_corr_usegray: Uses a machine learning algorithm to learn the pattern of local voxel-level errors in the label fusion process. This is the best output if the subject's image contrast is very similar to the one in the atlas (generally true)
  3. _lfseg_corr_usegray: Similar to the previous one, but without taking the intensity into account. This is the best if the contrast is different (values of 100-200 in the atlas vs 500-700 in the subject's image for example)

The ASHS mask output is in .nii.gz format, which can be viewed, but not edited with Minc tools.

3.1 Quality control

One of the most crucial steps is to make sure that ASHS does the job correctly. This is best achieved with Display, which is described in another guide. The left and right segmentations can be QCed at the same time. The for loop would look like this:

   for i in *t1.nii ; do Display -gray -range 50 220 $i 
   -label ${i:0:14}/final/${i:0:14}_left_lfseg_corr_usegray.nii.gz -label ${i:0:14}/final/${i:0:14}_right_lfseg_corr_usegray.nii.gz
   ; done

Alternatively, you can create a file list:

   for i in $(cat /home/etienne/Desktop/ASHS_QC.txt); 
   do Display -gray -range 50 220 $i/${i}_t1.nii -label ${i:0:15}/final/${i:0:15}_left_lfseg_corr_usegray.nii.gz 
   -label ${i:0:15}/final/${i:0:15}_right_lfseg_corr_usegray.nii.gz ; done

The labels are:

  • Purple: PRC
  • Lightest teal: TEC
  • Second lightest teal: EC
  • Dark teal: white matter within the MTL
  • Dark red: rhinal sulcus
  • Dark green: collateral sulcus
  • Red: anterior hippocampus
  • Bright Green: posterior hippocampus
  • White: parahippocampal cortex
  • Green: dural matter
  • Dark purple: hippocampal sulcus (usually relatively poorly segmented)

I recommend using the 5-point scale described in this guide to rate the images. It's better to be more stringent when the masks are intended for use with PET images. Exclude the data with poor quality output.

Several images will be very close to being acceptable due to 1-2 labels that have been poorly segmented. You may specify them in your QC list and manually correct them in a second pass. However, you need to convert the images to .mnc to edit them with Display.

   for i in * ; do nii2mnc $i/final/${i:0:14}*_lfseg_corr_usegray.nii.gz ; done

Note: If you manually edit images, don't use the .txt output - they won't be valid anymore. Just extract the volume as explained in the MincTools 101 guide.

3.2 Using the masks on PET images

To extract SUVR values within ASHS labels, you'll first need to match the PET images with the correct MRI. The MCSA sheet contains this information. You'll need an MRI-space SUVR image (which should be available in late 2024). Refer to the MincTools 101 guide for the SUVR extraction.

Note: sometimes, the images' dimensions don't quite fit (creates an error with mincstats). You may need to resample the PET image to the labels. If you do, double-check the alignment of the PET with the MRI in case of an error.

Clone this wiki locally