Skip to content

Commit

Permalink
5ttgen deep_atropos: Fixes to example usages
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Lestropie committed Jan 21, 2025
1 parent fd3aa5b commit ee90596
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/reference/commands/5ttgen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
20 changes: 11 additions & 9 deletions python/mrtrix3/commands/5ttgen/deep_atropos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down

0 comments on commit ee90596

Please sign in to comment.