Skip to content

Commit f7558b9

Browse files
committed
Merge pull request #966 from armaneshaghi/antsVisualization
ANTs visualization module
2 parents b90c82e + c4a30d6 commit f7558b9

File tree

6 files changed

+160
-4
lines changed

6 files changed

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

nipype/testing/data/mask.nii.gz

Whitespace-only changes.

nipype/testing/data/rgb.nii.gz

Whitespace-only changes.

0 commit comments

Comments
 (0)