References
- Paper: Geodesic Information Flows: Spatially-Variant Graphs and Their Application to Segmentation and Fusion
- Reference c++ implementation: https://github.com/KCL-BMEIS/gif
- Register all atlas images to the image to be segmented (target image) and resample the atlas images into the target image space. The registration is performed using the NiftyReg library. First, an affine registration is performed using reg_aladin, then a non-linear registration is performed using reg_f3d.
- Resample the atlas segmentations into the space of the target image using the transformation computed in step 1. This is done using reg_resample from the NiftyReg library.
- Compute weights that indicate the similarity between the target image and each atlas image. The weights are based on the Local Normalized Cross Correlation (LNCC) between the target image and each atlas image.
- Fuse the resampled atlas segmentations using the weights computed in step 3 to obtain a probability map of the segmentation of the target image for each label present in the atlas segmentations.
- Using an input mapping between the labels and a much smaller number of tissue classes (gray matter, white matter, etc.), distribute the label probabilities to the tissue classes to create a tissues segmentation prior.
- Use the tissue segmentation prior and the target image as input to an Expectation Maximization algorithm to obtain the final tissue segmentation of the target image. This is done using the seg_EM binary from the NiftySeg library.
- Create the final segmentation of the target image by assigning each voxel to the label with the highest probability that matches the tissue segmentation obtained in step 6 according to the input mapping between labels and tissue
- classes.
The code has been tested with the configuration:
- Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
The following python libraries are required:
- numpy
- nibabel
- scipy
- pandas
- numba
They can be installed with pip:
pip install numpy nibabel scipy pandas numba
A test script is provided here: run_multi_atlas_segmentation_downsampled_test.py
6 arguments need to be defined:
img_path: path to the image to be segmentedmask_path: path to the mask of the image to be segmented (1 for the region of interest, 0 for the background)atlas_dir_list: list of paths to the atlas folder (each atlas folder contains the atlas image and the atlas segmentation)results_dir: path to the folder where the results will be savedstructure_info_csv_path: path to the csv file containing labels numbers, label names and the mapping between the labels in the atlas segmentations to the tissue classes, for example: 8,Right Accumbens Area,"[3, 4]"tissue_info_csv_path: path to the csv file containing labels and names of the tissue classes: for example: 3, White Matter
The script will create the following output in the results_dir:
<atlas_name>folder for each atlas inatlas_dir_list. Each folder contains the following:warped_atlas_image.nii.gzThe atlas image resampled into the space of the target imagewarped_atlas_seg.nii.gzThe atlas segmentation resampled into the space of the target imageweights.nii.gzThe weights computed for each atlas image- some other temporary files used or created by NiftyReg
multi_atlas_tissue_prior.nii.gzThe tissue segmentation priormulti_atlas_tissue_seg.nii.gzThe final tissue segmentation of the target imagefinal_parcellation.nii.gzThe final parcellation (multi-atlas segmentation) of the target image
Multiprocessing options, parameters for Niftyreg and Niftyseg, and other options can be modified in the definitions.py file.