# Copyright (c) 2008-2021 the MRtrix3 contributors.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Covered Software is provided under this License on an "as is"
# basis, without warranty of any kind, either expressed, implied, or
# statutory, including, without limitation, warranties that the
# Covered Software is free of defects, merchantable, fit for a
# particular purpose or non-infringing.
# See the Mozilla Public License v. 2.0 for more details.
#
# For more details, see http://www.mrtrix.org/.

# This file is used to extract sub-cortical structures from FreeSurfer segmentations

# Previously, the labelsgmfix command was compatible with both FreeSurfer LUT files and connectome config files, as the first two columns were identical. Now, this command ideally needs to be compatible with LUT files in any format.

# This is solved in the following way:
# * Create a new image for sub-cortical structures using the output of FIRST and these indices.
# * Convert that image to the indices of the original lookup table using labelconvert.
# * Use mrstats to 'discover' what index each structure has been assigned to.
# * For each index in the original image, strip out any voxels corresponding to any of these values.
# * Also zero any voxels that coincide with any of the new SGM estimates.
# * Add the re-indexed SGM image to the stripped input image.


1  Left-Thalamus-Proper
2  Left-Caudate
3  Left-Putamen
4  Left-Pallidum
5  Left-Accumbens-area

6  Right-Thalamus-Proper
7  Right-Caudate
8  Right-Putamen
9  Right-Pallidum
10 Right-Accumbens-area

11 Left-Hippocampus
12 Left-Amygdala
13 Right-Hippocampus
14 Right-Amygdala

