Skip to content

Commit 68bf22e

Browse files
committed
ANTs visualization module
1 parent 0311234 commit 68bf22e

File tree

4 files changed

+153
-4
lines changed

4 files changed

+153
-4
lines changed

nipype/interfaces/ants/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
# Segmentation Programs
1414
from .segmentation import Atropos, LaplacianThickness, N4BiasFieldCorrection
1515

16+
# Visualization Programs
17+
from .visualization import ConvertScalarImageToRGB
18+
1619
# Utility Programs
1720
from .utils import AverageAffineTransform, AverageImages, MultiplyImages, JacobianDeterminant

nipype/interfaces/ants/resampling.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
2-
# vi: set ft = python sts = 4 ts = 4 sw = 4 et:
31
"""ANTS Apply Transforms interface
42
53
Change directory to provide relative paths for doctests

nipype/interfaces/ants/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
2-
# vi: set ft = python sts = 4 ts = 4 sw = 4 et:
31
"""ANTS Apply Transforms interface
42
53
Change directory to provide relative paths for doctests
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
"""The ants visualisation module provides basic functions based on ITK.
2+
Change directory to provide relative paths for doctests
3+
>>> import os
4+
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
5+
>>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))
6+
>>> os.chdir(datadir)
7+
"""
8+
9+
from ..base import (TraitedSpec, File, traits)
10+
from .base import ANTSCommand, ANTSCommandInputSpec
11+
import os
12+
from nipype.interfaces.base import InputMultiPath
13+
from nipype.interfaces.traits_extension import isdefined
14+
import numpy as np
15+
16+
class ConvertScalarImageToRGBInputSpec(ANTSCommandInputSpec):
17+
dimension=traits.Enum(3, 2, argstr= '%d', usedefault=True,
18+
desc='image dimension (2 or 3)', mandatory=True,
19+
position = 0)
20+
input_image=File(argstr='%s', exists=True,
21+
desc='Main input is a 3-D grayscale image.', mandatory=True,
22+
position = 1)
23+
output_image=traits.Str('rgb.nii.gz', argstr='%s', usedefault=True,
24+
desc=('rgb output image'), position = 2)
25+
mask_image=File('none', argstr='%s', exists=True,
26+
desc = 'mask image', position = 3)
27+
colormap=traits.Str(argstr='%s', usedefault=True,
28+
desc=('Possible colormaps: grey, red, green, '
29+
'blue, copper, jet, hsv, spring, summer, '
30+
'autumn, winter, hot, cool, overunder, custom '
31+
), mandatory = True, position = 4)
32+
custom_color_map_file=traits.Str('none', argstr='%s', usedefault=True,
33+
desc = 'custom color map file', position = 5)
34+
minimum_input = traits.Int(argstr='%d', desc='minimum input',
35+
mandatory = True, position = 6)
36+
maximum_input = traits.Int(argstr='%d', desc='maximum input',
37+
mandatory = True, position = 7)
38+
minimum_RGB_output = traits.Int(0, usedefault=True,
39+
argstr='%d', desc = '', position = 8)
40+
maximum_RGB_output = traits.Int(255, usedefault=True,
41+
argstr='%d', desc = '', position = 9)
42+
43+
class ConvertScalarImageToRGBOutputSpec(TraitedSpec):
44+
output_image= File(exists=True, desc='converted RGB image')
45+
46+
class ConvertScalarImageToRGB(ANTSCommand):
47+
"""
48+
Examples
49+
--------
50+
>>> from nipype.interfaces.ants.visualization import ConvertScalarImageToRGB
51+
>>> converter = ConvertScalarImageToRGB()
52+
>>> converter.inputs.dimension = 3
53+
>>> converter.inputs.input_image = 'T1.nii.gz'
54+
>>> converter.inputs.colormap = 'jet'
55+
>>> converter.inputs.minimum_input = 0
56+
>>> converter.inputs.maximum_input = 6
57+
>>> converter.cmdline
58+
'ConvertScalarImageToRGB 3 T1.nii.gz rgb.nii.gz none jet none 0 6 0 255'
59+
"""
60+
_cmd = 'ConvertScalarImageToRGB'
61+
input_spec = ConvertScalarImageToRGBInputSpec
62+
output_spec = ConvertScalarImageToRGBOutputSpec
63+
64+
def _format_arg(self, opt, spec, val):
65+
return super(ConvertScalarImageToRGB, self)._format_arg(opt, spec, val)
66+
67+
def _list_outputs(self):
68+
outputs = self._outputs().get()
69+
outputs['output_image'] = os.path.join(os.getcwd(),
70+
self.inputs.output_image)
71+
return outputs
72+
73+
74+
class CreateTiledMosaicInputSpec(ANTSCommandInputSpec):
75+
input_image = File(argstr='-i %s', exists=True,
76+
desc = 'Main input is a 3-D grayscale image.',
77+
mandatory = True)
78+
rgb_image= File(argstr='-r %s', exists = True,
79+
desc = ('An optional Rgb image can be added as an overlay.'
80+
'It must have the same image'
81+
'geometry as the input grayscale image.'),
82+
mandatory = True)
83+
mask_image = File(argstr = '-x %s', exists = True,
84+
desc = 'Specifies the ROI of the RGB voxels used.')
85+
alpha_value = traits.Float(argstr = '-a %f',
86+
desc = ('If an Rgb image is provided, render the overlay '
87+
'using the specified alpha parameter.'))
88+
output_image = traits.Str(argstr = '-o %s',
89+
desc = 'The output consists of the tiled mosaic image.')
90+
tile_geometry = traits.Str(argstr = '%s',
91+
desc = (
92+
'The tile geometry specifies the number of rows and columns'
93+
'in the output image. For example, if the user specifies ''5x10'', '
94+
'then 5 rows by 10 columns of slices are rendered. If R < 0 and C > '
95+
'0 (or vice versa), the negative value is selected'
96+
'based on direction.')
97+
direction = traits.Int(argstr = '%d', desc = ('Specifies the direction of '
98+
'the slices. If no direction is specified, the '
99+
'direction with the coarsest spacing is chosen.'))
100+
pad_or_crop = traits.Str(argstr='-p %s',
101+
desc = 'argument passed to -p flag:'
102+
'[padVoxelWidth,<constantValue=0>]'
103+
'[lowerPadding[0]xlowerPadding[1],upperPadding[0]xupperPadding[1],'
104+
'constantValue]'
105+
'The user can specify whether to pad or crop a specified '
106+
'voxel-width boundary of each individual slice. For this '
107+
'program, cropping is simply padding with negative voxel-widths.'
108+
'If one pads (+), the user can also specify a constant pad '
109+
'value (default = 0). If a mask is specified, the user can use '
110+
'the mask to define the region, by using the keyword "mask"'
111+
' plus an offset, e.g. "-p mask+3".'
112+
)
113+
slices = traits.Str(argstr='-s %s',
114+
desc = ('Number of slices to increment Slice1xSlice2xSlice3'
115+
'[numberOfSlicesToIncrement,<minSlice=0>,<maxSlice=lastSlice>]'))
116+
flip_slice = traits.Str(argstr = '-f %s',
117+
desc = ('flipXxflipY'))
118+
permute_axes = traits.Bool(argstr = '-g', desc = 'doPermute'
119+
)
120+
121+
122+
class CreateTiledMosaicOutputSpec(TraitedSpec):
123+
output_image= File(exists=True, desc='image file')
124+
125+
class CreateTiledMosaicOutputSpec(ANTSCommand):
126+
"""The program CreateTiledMosaic in conjunction with ConvertScalarImageToRGB
127+
provides useful functionality for common image analysis tasks. The basic
128+
usage of CreateTiledMosaic is to tile a 3-D image volume slice-wise into
129+
a 2-D image.
130+
131+
Examples
132+
--------
133+
134+
>>> from nipype.interfaces.ants.visualization import CreateTiledMosaic
135+
>>> mosaic_slicer = CreateTiledMosaic()
136+
>>> mosaic_slicer.inputs.dimension = 3
137+
>>> mosaic_slicer.inputs.input_image = 'T1.nii.gz'
138+
>>> mosaic_slicer.inputs.colormap = 'jet'
139+
>>>
140+
141+
"""
142+
143+
_cmd = 'CreateTiledMosaic'
144+
input_spec = CreateTiledMosaicInputSpec
145+
output_spec = CreateTiledMosaicInputSpecOutputSpec
146+
147+
def _list_outputs(self):
148+
outputs = self._outputs().get()
149+
outputs['output_image'] = os.path.join(os.getcwd(),
150+
self.inputs.output_image)

0 commit comments

Comments
 (0)