Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5ttgen: Add Deep Atropos algorithm #3057

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
Prev Previous commit
Next Next commit
5ttgen deep_atropos: Fixes to example usages
- Fix use of single vs double quotes so that examples can be copy-pasted into a terminal and executed successfully.
- Load the input image a second time using nibabel to get the affine transformation; the ANTsImage class modifies both the content and the representation of this information, and does not contain a member variable ".affine" as utilised in the original example.
Lestropie committed Jan 21, 2025
commit ee9059685fc5af3f04633196e47b851e30743b52
4 changes: 2 additions & 2 deletions docs/reference/commands/5ttgen.rst
Original file line number Diff line number Diff line change
@@ -122,13 +122,13 @@ Example usages

- *To utilise the "segmentation" image*::

$ python3 -c 'import ants, antspynet; t1w = ants.image_read('T1w.nii.gz'); result = antspynet.deep_atropos(t1w); ants.image_write'result['segmentation_image'], 'segmentation.nii.gz')'; 5ttgen deep_atropos segmentation.nii.gz 5tt_segmentation.mif
$ python3 -c "import ants, antspynet; t1w = ants.image_read('T1w.nii.gz'); result = antspynet.deep_atropos(t1w); ants.image_write(result['segmentation_image'], 'segmentation.nii.gz')"; 5ttgen deep_atropos segmentation.nii.gz 5tt_segmentation.mif

Because the input segmentation here is an integer image, where each voxel just contains an index corresponding to the maximal tissue class, the output 5TT image will not possess any fractional partial volumes; it will just contain the value 1.0 in whichever 5TT volume corresponds to the singular assigned tissue class.

- *To utilise the "probability images"*::

$ python3 -c 'import ants, antspynet, nibabel, numpy; t1w = ants.image_read('T1w.nii.gz'); result = antspynet.deep_atropos(t1w); prob_maps = numpy.stack([numpy.array(img.numpy()) for img in result['probability_images']], axis=-1); nibabel.save(nib.Nifti1Image(prob_maps, t1w.affine), 'probabilities.nii.gz')'; 5ttgen deep_atropos probabilities.nii.gz 5tt_probabilities.mif
$ python3 -c "import ants, antspynet, nibabel, numpy; inpath = 'T1w.nii.gz'; t1w_ants = ants.image_read(inpath); t1w_nib = nibabel.load(inpath); result = antspynet.deep_atropos(t1w_ants); prob_maps = numpy.stack([numpy.array(img.numpy()) for img in result['probability_images']], axis=-1); nibabel.save(nibabel.Nifti1Image(prob_maps, t1w_nib.affine), 'probabilities.nii.gz')"; 5ttgen deep_atropos probabilities.nii.gz 5tt_probabilities.mif

In this use case, the poerior probabilities of these tissue classes are interpreted as partial volume fractions and imported into the derivative 5TT image appropriately.

20 changes: 11 additions & 9 deletions python/mrtrix3/commands/5ttgen/deep_atropos.py
Original file line number Diff line number Diff line change
@@ -40,21 +40,23 @@ def usage(base_parser, subparsers): #pylint: disable=unused-variable
'require that "ants" and "antspynet" be installed via Python\'s "pip"; '
'use of the "probability images" also requires that nibabel and numpy be installed.')
parser.add_example_usage('To utilise the "segmentation" image',
'python3 -c \'import ants, antspynet; '
't1w = ants.image_read(\'T1w.nii.gz\'); '
'result = antspynet.deep_atropos(t1w); '
'ants.image_write\'result[\'segmentation_image\'], \'segmentation.nii.gz\')\'; '
'python3 -c "import ants, antspynet; '
't1w = ants.image_read(\'T1w.nii.gz\'); '
'result = antspynet.deep_atropos(t1w); '
'ants.image_write(result[\'segmentation_image\'], \'segmentation.nii.gz\')"; '
'5ttgen deep_atropos segmentation.nii.gz 5tt_segmentation.mif',
'Because the input segmentation here is an integer image, '
'where each voxel just contains an index corresponding to the maximal tissue class, '
'the output 5TT image will not possess any fractional partial volumes; '
'it will just contain the value 1.0 in whichever 5TT volume corresponds to the singular assigned tissue class.')
parser.add_example_usage('To utilise the "probability images"',
'python3 -c \'import ants, antspynet, nibabel, numpy; '
't1w = ants.image_read(\'T1w.nii.gz\'); '
'result = antspynet.deep_atropos(t1w); '
'prob_maps = numpy.stack([numpy.array(img.numpy()) for img in result[\'probability_images\']], axis=-1); '
'nibabel.save(nib.Nifti1Image(prob_maps, t1w.affine), \'probabilities.nii.gz\')\'; '
'python3 -c "import ants, antspynet, nibabel, numpy; '
'inpath = \'T1w.nii.gz\'; '
't1w_ants = ants.image_read(inpath); '
't1w_nib = nibabel.load(inpath); '
'result = antspynet.deep_atropos(t1w_ants); '
'prob_maps = numpy.stack([numpy.array(img.numpy()) for img in result[\'probability_images\']], axis=-1); '
'nibabel.save(nibabel.Nifti1Image(prob_maps, t1w_nib.affine), \'probabilities.nii.gz\')"; '
'5ttgen deep_atropos probabilities.nii.gz 5tt_probabilities.mif',
'In this use case, the poerior probabilities of these tissue classes are interpreted as partial volume fractions '
'and imported into the derivative 5TT image appropriately.')