nipype.interfaces.niftyseg.maths module

Nipype interface for seg_maths.

The maths module provides higher-level interfaces to some of the operations that can be performed with the niftysegmaths (seg_maths) command-line program.

BinaryMaths

Link to code

Bases: MathsCommand

Wrapped executable: seg_maths.

Binary mathematical operations.

See also

Source codeDocumentation

Examples

>>> import copy
>>> from nipype.interfaces import niftyseg
>>> binary = niftyseg.BinaryMaths()
>>> binary.inputs.in_file = 'im1.nii'
>>> binary.inputs.output_datatype = 'float'
>>> # Test sub operation
>>> binary_sub = copy.deepcopy(binary)
>>> binary_sub.inputs.operation = 'sub'
>>> binary_sub.inputs.operand_file = 'im2.nii'
>>> binary_sub.cmdline
'seg_maths im1.nii -sub im2.nii -odt float im1_sub.nii'
>>> binary_sub.run()  
>>> # Test mul operation
>>> binary_mul = copy.deepcopy(binary)
>>> binary_mul.inputs.operation = 'mul'
>>> binary_mul.inputs.operand_value = 2.0
>>> binary_mul.cmdline
'seg_maths im1.nii -mul 2.00000000 -odt float im1_mul.nii'
>>> binary_mul.run()  
>>> # Test llsnorm operation
>>> binary_llsnorm = copy.deepcopy(binary)
>>> binary_llsnorm.inputs.operation = 'llsnorm'
>>> binary_llsnorm.inputs.operand_file = 'im2.nii'
>>> binary_llsnorm.cmdline
'seg_maths im1.nii -llsnorm im2.nii -odt float im1_llsnorm.nii'
>>> binary_llsnorm.run()  
>>> # Test splitinter operation
>>> binary_splitinter = copy.deepcopy(binary)
>>> binary_splitinter.inputs.operation = 'splitinter'
>>> binary_splitinter.inputs.operand_str = 'z'
>>> binary_splitinter.cmdline
'seg_maths im1.nii -splitinter z -odt float im1_splitinter.nii'
>>> binary_splitinter.run()  
in_filea pathlike object or string representing an existing file

Image to operate on. Maps to a command-line argument: %s (position: 2).

operand_filea pathlike object or string representing an existing file

Second image to perform operation with. Maps to a command-line argument: %s (position: 5). Mutually exclusive with inputs: operand_value, operand_str.

operand_str‘x’ or ‘y’ or ‘z’

String value to perform operation splitinter. Maps to a command-line argument: %s (position: 5). Mutually exclusive with inputs: operand_value, operand_file.

operand_valuea float

Float value to perform operation with. Maps to a command-line argument: %.8f (position: 5). Mutually exclusive with inputs: operand_file, operand_str.

operation‘mul’ or ‘div’ or ‘add’ or ‘sub’ or ‘pow’ or ‘thr’ or ‘uthr’ or ‘smo’ or ‘edge’ or ‘sobel3’ or ‘sobel5’ or ‘min’ or ‘smol’ or ‘geo’ or ‘llsnorm’ or ‘masknan’ or ‘hdr_copy’ or ‘splitinter’

Operation to perform:

  • mul - <float/file> - Multiply image <float> value or by other image.

  • div - <float/file> - Divide image by <float> or by other image.

  • add - <float/file> - Add image by <float> or by other image.

  • sub - <float/file> - Subtract image by <float> or by other image.

  • pow - <float> - Image to the power of <float>.

  • thr - <float> - Threshold the image below <float>.

  • uthr - <float> - Threshold image above <float>.

  • smo - <float> - Gaussian smoothing by std <float> (in voxels and up to 4-D).

  • edge - <float> - Calculate the edges of the image using a threshold <float>.

  • sobel3 - <float> - Calculate the edges of all timepoints using a Sobel filter with a 3x3x3 kernel and applying <float> gaussian smoothing.

  • sobel5 - <float> - Calculate the edges of all timepoints using a Sobel filter with a 5x5x5 kernel and applying <float> gaussian smoothing.

  • min - <file> - Get the min per voxel between <current> and <file>.

  • smol - <float> - Gaussian smoothing of a 3D label image.

  • geo - <float/file> - Geodesic distance according to the speed function <float/file>

  • llsnorm <file_norm> - Linear LS normalisation between current and <file_norm>

  • masknan <file_norm> - Assign everything outside the mask (mask==0) with NaNs

  • hdr_copy <file> - Copy header from working image to <file> and save in <output>.

  • splitinter <x/y/z> - Split interleaved slices in direction <x/y/z> into separate time points

Maps to a command-line argument: -%s (position: 4).

argsa string

Additional parameters to the command. Maps to a command-line argument: %s.

environa dictionary with keys which are a bytes or None or a value of class ‘str’ and with values which are a bytes or None or a value of class ‘str’

Environment variables. (Nipype default value: {})

out_filea pathlike object or string representing a file

Image to write. Maps to a command-line argument: %s (position: -2).

output_datatype‘float’ or ‘char’ or ‘int’ or ‘short’ or ‘double’ or ‘input’

Datatype to use for output (default uses input type). Maps to a command-line argument: -odt %s (position: -3).

out_filea pathlike object or string representing a file

Image written after calculations.

BinaryMathsInteger

Link to code

Bases: MathsCommand

Wrapped executable: seg_maths.

Integer mathematical operations.

See also

Source codeDocumentation

Examples

>>> import copy
>>> from nipype.interfaces.niftyseg import BinaryMathsInteger
>>> binaryi = BinaryMathsInteger()
>>> binaryi.inputs.in_file = 'im1.nii'
>>> binaryi.inputs.output_datatype = 'float'
>>> # Test dil operation
>>> binaryi_dil = copy.deepcopy(binaryi)
>>> binaryi_dil.inputs.operation = 'dil'
>>> binaryi_dil.inputs.operand_value = 2
>>> binaryi_dil.cmdline
'seg_maths im1.nii -dil 2 -odt float im1_dil.nii'
>>> binaryi_dil.run()  
>>> # Test dil operation
>>> binaryi_ero = copy.deepcopy(binaryi)
>>> binaryi_ero.inputs.operation = 'ero'
>>> binaryi_ero.inputs.operand_value = 1
>>> binaryi_ero.cmdline
'seg_maths im1.nii -ero 1 -odt float im1_ero.nii'
>>> binaryi_ero.run()  
>>> # Test pad operation
>>> binaryi_pad = copy.deepcopy(binaryi)
>>> binaryi_pad.inputs.operation = 'pad'
>>> binaryi_pad.inputs.operand_value = 4
>>> binaryi_pad.cmdline
'seg_maths im1.nii -pad 4 -odt float im1_pad.nii'
>>> binaryi_pad.run()  
in_filea pathlike object or string representing an existing file

Image to operate on. Maps to a command-line argument: %s (position: 2).

operand_valuean integer

Int value to perform operation with. Maps to a command-line argument: %d (position: 5).

operation‘dil’ or ‘ero’ or ‘tp’ or ‘equal’ or ‘pad’ or ‘crop’

Operation to perform:

  • equal - <int> - Get voxels equal to <int>

  • dil - <int> - Dilate the image <int> times (in voxels).

  • ero - <int> - Erode the image <int> times (in voxels).

  • tp - <int> - Extract time point <int>

  • crop - <int> - Crop <int> voxels around each 3D volume.

  • pad - <int> - Pad <int> voxels with NaN value around each 3D volume.

Maps to a command-line argument: -%s (position: 4).

argsa string

Additional parameters to the command. Maps to a command-line argument: %s.

environa dictionary with keys which are a bytes or None or a value of class ‘str’ and with values which are a bytes or None or a value of class ‘str’

Environment variables. (Nipype default value: {})

out_filea pathlike object or string representing a file

Image to write. Maps to a command-line argument: %s (position: -2).

output_datatype‘float’ or ‘char’ or ‘int’ or ‘short’ or ‘double’ or ‘input’

Datatype to use for output (default uses input type). Maps to a command-line argument: -odt %s (position: -3).

out_filea pathlike object or string representing a file

Image written after calculations.

MathsCommand

Link to code

Bases: NiftySegCommand

Wrapped executable: seg_maths.

Base Command Interface for seg_maths interfaces.

The executable seg_maths enables the sequential execution of arithmetic operations, like multiplication (-mul), division (-div) or addition (-add), binarisation (-bin) or thresholding (-thr) operations and convolution by a Gaussian kernel (-smo). It also alows mathematical morphology based operations like dilation (-dil), erosion (-ero), connected components (-lconcomp) and hole filling (-fill), Euclidean (- euc) and geodesic (-geo) distance transforms, local image similarity metric calculation (-lncc and -lssd). Finally, it allows multiple operations over the dimensionality of the image, from merging 3D images together as a 4D image (-merge) or splitting (-split or -tp) 4D images into several 3D images, to estimating the maximum, minimum and average over all time-points, etc.

in_filea pathlike object or string representing an existing file

Image to operate on. Maps to a command-line argument: %s (position: 2).

argsa string

Additional parameters to the command. Maps to a command-line argument: %s.

environa dictionary with keys which are a bytes or None or a value of class ‘str’ and with values which are a bytes or None or a value of class ‘str’

Environment variables. (Nipype default value: {})

out_filea pathlike object or string representing a file

Image to write. Maps to a command-line argument: %s (position: -2).

output_datatype‘float’ or ‘char’ or ‘int’ or ‘short’ or ‘double’ or ‘input’

Datatype to use for output (default uses input type). Maps to a command-line argument: -odt %s (position: -3).

out_filea pathlike object or string representing a file

Image written after calculations.

Merge

Link to code

Bases: MathsCommand

Wrapped executable: seg_maths.

Merge image files.

See also

Source codeDocumentation

Examples

>>> from nipype.interfaces import niftyseg
>>> node = niftyseg.Merge()
>>> node.inputs.in_file = 'im1.nii'
>>> files = ['im2.nii', 'im3.nii']
>>> node.inputs.merge_files = files
>>> node.inputs.dimension = 2
>>> node.inputs.output_datatype = 'float'
>>> node.cmdline
'seg_maths im1.nii -merge 2 2 im2.nii im3.nii -odt float im1_merged.nii'
dimensionan integer

Dimension to merge the images.

in_filea pathlike object or string representing an existing file

Image to operate on. Maps to a command-line argument: %s (position: 2).

merge_filesa list of items which are a pathlike object or string representing an existing file

List of images to merge to the working image <input>. Maps to a command-line argument: %s (position: 4).

argsa string

Additional parameters to the command. Maps to a command-line argument: %s.

environa dictionary with keys which are a bytes or None or a value of class ‘str’ and with values which are a bytes or None or a value of class ‘str’

Environment variables. (Nipype default value: {})

out_filea pathlike object or string representing a file

Image to write. Maps to a command-line argument: %s (position: -2).

output_datatype‘float’ or ‘char’ or ‘int’ or ‘short’ or ‘double’ or ‘input’

Datatype to use for output (default uses input type). Maps to a command-line argument: -odt %s (position: -3).

out_filea pathlike object or string representing a file

Image written after calculations.

TupleMaths

Link to code

Bases: MathsCommand

Wrapped executable: seg_maths.

Mathematical operations on tuples.

See also

Source codeDocumentation

Examples

>>> import copy
>>> from nipype.interfaces import niftyseg
>>> tuple = niftyseg.TupleMaths()
>>> tuple.inputs.in_file = 'im1.nii'
>>> tuple.inputs.output_datatype = 'float'
>>> # Test lncc operation
>>> tuple_lncc = copy.deepcopy(tuple)
>>> tuple_lncc.inputs.operation = 'lncc'
>>> tuple_lncc.inputs.operand_file1 = 'im2.nii'
>>> tuple_lncc.inputs.operand_value2 = 2.0
>>> tuple_lncc.cmdline
'seg_maths im1.nii -lncc im2.nii 2.00000000 -odt float im1_lncc.nii'
>>> tuple_lncc.run()  
>>> # Test lssd operation
>>> tuple_lssd = copy.deepcopy(tuple)
>>> tuple_lssd.inputs.operation = 'lssd'
>>> tuple_lssd.inputs.operand_file1 = 'im2.nii'
>>> tuple_lssd.inputs.operand_value2 = 1.0
>>> tuple_lssd.cmdline
'seg_maths im1.nii -lssd im2.nii 1.00000000 -odt float im1_lssd.nii'
>>> tuple_lssd.run()  
>>> # Test lltsnorm operation
>>> tuple_lltsnorm = copy.deepcopy(tuple)
>>> tuple_lltsnorm.inputs.operation = 'lltsnorm'
>>> tuple_lltsnorm.inputs.operand_file1 = 'im2.nii'
>>> tuple_lltsnorm.inputs.operand_value2 = 0.01
>>> tuple_lltsnorm.cmdline
'seg_maths im1.nii -lltsnorm im2.nii 0.01000000 -odt float im1_lltsnorm.nii'
>>> tuple_lltsnorm.run()  
in_filea pathlike object or string representing an existing file

Image to operate on. Maps to a command-line argument: %s (position: 2).

operand_file1a pathlike object or string representing an existing file

Image to perform operation 1 with. Maps to a command-line argument: %s (position: 5). Mutually exclusive with inputs: operand_value1.

operand_file2a pathlike object or string representing an existing file

Image to perform operation 2 with. Maps to a command-line argument: %s (position: 6). Mutually exclusive with inputs: operand_value2.

operand_value1a float

Float value to perform operation 1 with. Maps to a command-line argument: %.8f (position: 5). Mutually exclusive with inputs: operand_file1.

operand_value2a float

Float value to perform operation 2 with. Maps to a command-line argument: %.8f (position: 6). Mutually exclusive with inputs: operand_file2.

operation‘lncc’ or ‘lssd’ or ‘lltsnorm’

Operation to perform:

  • lncc <file> <std> Local CC between current img and <file> on a kernel with <std>

  • lssd <file> <std> Local SSD between current img and <file> on a kernel with <std>

  • lltsnorm <file_norm> <float> Linear LTS normalisation assuming <float> percent outliers

Maps to a command-line argument: -%s (position: 4).

argsa string

Additional parameters to the command. Maps to a command-line argument: %s.

environa dictionary with keys which are a bytes or None or a value of class ‘str’ and with values which are a bytes or None or a value of class ‘str’

Environment variables. (Nipype default value: {})

out_filea pathlike object or string representing a file

Image to write. Maps to a command-line argument: %s (position: -2).

output_datatype‘float’ or ‘char’ or ‘int’ or ‘short’ or ‘double’ or ‘input’

Datatype to use for output (default uses input type). Maps to a command-line argument: -odt %s (position: -3).

out_filea pathlike object or string representing a file

Image written after calculations.

UnaryMaths

Link to code

Bases: MathsCommand

Wrapped executable: seg_maths.

Unary mathematical operations.

See also

Source codeDocumentation

Examples

>>> import copy
>>> from nipype.interfaces import niftyseg
>>> unary = niftyseg.UnaryMaths()
>>> unary.inputs.output_datatype = 'float'
>>> unary.inputs.in_file = 'im1.nii'
>>> # Test sqrt operation
>>> unary_sqrt = copy.deepcopy(unary)
>>> unary_sqrt.inputs.operation = 'sqrt'
>>> unary_sqrt.cmdline
'seg_maths im1.nii -sqrt -odt float im1_sqrt.nii'
>>> unary_sqrt.run()  
>>> # Test sqrt operation
>>> unary_abs = copy.deepcopy(unary)
>>> unary_abs.inputs.operation = 'abs'
>>> unary_abs.cmdline
'seg_maths im1.nii -abs -odt float im1_abs.nii'
>>> unary_abs.run()  
>>> # Test bin operation
>>> unary_bin = copy.deepcopy(unary)
>>> unary_bin.inputs.operation = 'bin'
>>> unary_bin.cmdline
'seg_maths im1.nii -bin -odt float im1_bin.nii'
>>> unary_bin.run()  
>>> # Test otsu operation
>>> unary_otsu = copy.deepcopy(unary)
>>> unary_otsu.inputs.operation = 'otsu'
>>> unary_otsu.cmdline
'seg_maths im1.nii -otsu -odt float im1_otsu.nii'
>>> unary_otsu.run()  
>>> # Test isnan operation
>>> unary_isnan = copy.deepcopy(unary)
>>> unary_isnan.inputs.operation = 'isnan'
>>> unary_isnan.cmdline
'seg_maths im1.nii -isnan -odt float im1_isnan.nii'
>>> unary_isnan.run()  
in_filea pathlike object or string representing an existing file

Image to operate on. Maps to a command-line argument: %s (position: 2).

operation‘sqrt’ or ‘exp’ or ‘log’ or ‘recip’ or ‘abs’ or ‘bin’ or ‘otsu’ or ‘lconcomp’ or ‘concomp6’ or ‘concomp26’ or ‘fill’ or ‘euc’ or ‘tpmax’ or ‘tmean’ or ‘tmax’ or ‘tmin’ or ‘splitlab’ or ‘removenan’ or ‘isnan’ or ‘subsamp2’ or ‘scl’ or ‘4to5’ or ‘range’

Operation to perform:

  • sqrt - Square root of the image).

  • exp - Exponential root of the image.

  • log - Log of the image.

  • recip - Reciprocal (1/I) of the image.

  • abs - Absolute value of the image.

  • bin - Binarise the image.

  • otsu - Otsu thresholding of the current image.

  • lconcomp - Take the largest connected component

  • concomp6 - Label the different connected components with a 6NN kernel

  • concomp26 - Label the different connected components with a 26NN kernel

  • fill - Fill holes in binary object (e.g. fill ventricle in brain mask).

  • euc - Euclidean distance transform

  • tpmax - Get the time point with the highest value (binarise 4D probabilities)

  • tmean - Mean value of all time points.

  • tmax - Max value of all time points.

  • tmin - Mean value of all time points.

  • splitlab - Split the integer labels into multiple timepoints

  • removenan - Remove all NaNs and replace then with 0

  • isnan - Binary image equal to 1 if the value is NaN and 0 otherwise

  • subsamp2 - Subsample the image by 2 using NN sampling (qform and sform scaled)

  • scl - Reset scale and slope info.

  • 4to5 - Flip the 4th and 5th dimension.

  • range - Reset the image range to the min max.

Maps to a command-line argument: -%s (position: 4).

argsa string

Additional parameters to the command. Maps to a command-line argument: %s.

environa dictionary with keys which are a bytes or None or a value of class ‘str’ and with values which are a bytes or None or a value of class ‘str’

Environment variables. (Nipype default value: {})

out_filea pathlike object or string representing a file

Image to write. Maps to a command-line argument: %s (position: -2).

output_datatype‘float’ or ‘char’ or ‘int’ or ‘short’ or ‘double’ or ‘input’

Datatype to use for output (default uses input type). Maps to a command-line argument: -odt %s (position: -3).

out_filea pathlike object or string representing a file

Image written after calculations.