1
+ """
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 nipype .interfaces .base import (traits , TraitedSpec , File ,
10
+ CommandLine , CommandLineInputSpec , isdefined ,
11
+ InputMultiPath )
12
+ from nipype .utils .filemanip import split_filename
13
+ import os
14
+
15
+ class ImageStatsInputSpec (CommandLineInputSpec ):
16
+ in_files = InputMultiPath (File (exists = True ), argstr = '-images %s' , mandatory = True ,
17
+ position = - 1 , desc = ('List of images to process. They must '
18
+ 'be in the same space and have the same '
19
+ 'dimensions.' ))
20
+ stat = traits .Enum ("min" , "max" , "mean" , "median" , "sum" , "std" , "var" ,
21
+ argstr = '-stat %s' , units = 'NA' , mandatory = True ,
22
+ desc = "The statistic to compute." )
23
+
24
+ out_type = traits .Enum ("float" , "char" , "short" , "int" , "long" , "double" ,
25
+ argstr = '-outputdatatype %s' , usedefault = True ,
26
+ desc = ('A Camino data type string, default is "float". '
27
+ 'Type must be signed.' ))
28
+ output_root = File (argstr = '-outputroot %s' , mandatory = True ,
29
+ desc = ('Filename root prepended onto the names of the output '
30
+ ' files. The extension will be determined from the input.' ))
31
+
32
+ class ImageStatsOutputSpec (TraitedSpec ):
33
+ out_file = File (exists = True , desc = 'Path of the file computed with the statistic chosen' )
34
+
35
+ class ImageStats (CommandLine ):
36
+ """
37
+ This program computes voxelwise statistics on a series of 3D images. The images
38
+ must be in the same space; the operation is performed voxelwise and one output
39
+ is produced per voxel.
40
+
41
+ Examples
42
+ --------
43
+
44
+ >>> import nipype.interfaces.camino as cam
45
+ >>> imstats = cam.ImageStats()
46
+ >>> imstats.inputs.in_files = ['im1.nii','im2.nii','im3.nii']
47
+ >>> imstats.inputs.stat = 'max'
48
+ >>> imstats.run() # doctest: +SKIP
49
+ """
50
+ _cmd = 'imagestats'
51
+ input_spec = ImageStatsInputSpec
52
+ output_spec = ImageStatsOutputSpec
53
+
54
+ def _list_outputs (self ):
55
+ outputs = self .output_spec ().get ()
56
+ outputs ['out_file' ] = os .path .abspath (self ._gen_outfilename ())
57
+ return outputs
58
+
59
+ def _gen_outfilename (self ):
60
+ output_root = self .inputs .output_root
61
+ first_file = self .inputs .in_files [0 ]
62
+ _ , _ , ext = split_filename (first_file )
63
+ return output_root + ext
0 commit comments