nipype.interfaces.niftyseg.stats module

The stats module provides higher-level interfaces to some of the operations that can be performed with the niftyseg stats (seg_stats) command-line program.

BinaryStats

Link to code

Bases: StatsCommand

Wrapped executable: seg_stats.

Binary statistical operations.

See also

Source codeDocumentation

Examples

>>> import copy
>>> from nipype.interfaces import niftyseg
>>> binary = niftyseg.BinaryStats()
>>> binary.inputs.in_file = 'im1.nii'
>>> # Test sa operation
>>> binary_sa = copy.deepcopy(binary)
>>> binary_sa.inputs.operation = 'sa'
>>> binary_sa.inputs.operand_value = 2.0
>>> binary_sa.cmdline
'seg_stats im1.nii -sa 2.00000000'
>>> binary_sa.run()  
>>> # Test ncc operation
>>> binary_ncc = copy.deepcopy(binary)
>>> binary_ncc.inputs.operation = 'ncc'
>>> binary_ncc.inputs.operand_file = 'im2.nii'
>>> binary_ncc.cmdline
'seg_stats im1.nii -ncc im2.nii'
>>> binary_ncc.run()  
>>> # Test Nl operation
>>> binary_nl = copy.deepcopy(binary)
>>> binary_nl.inputs.operation = 'Nl'
>>> binary_nl.inputs.operand_file = 'output.csv'
>>> binary_nl.cmdline
'seg_stats im1.nii -Nl output.csv'
>>> binary_nl.run()  
Mandatory Inputs:
  • in_file (a pathlike object or string representing an existing file) – Image to operate on. Maps to a command-line argument: %s (position: 2).

  • operand_file (a 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_value (a float) – Value to perform operation with. Maps to a command-line argument: %.8f (position: 5). Mutually exclusive with inputs: operand_file.

  • operation (‘p’ or ‘sa’ or ‘ss’ or ‘svp’ or ‘al’ or ‘d’ or ‘ncc’ or ‘nmi’ or ‘Vl’ or ‘Nl’) –

    Operation to perform:

    • p - <float> - The <float>th percentile of all voxels intensity (float=[0,100])

    • sa - <ax> - Average of all voxels

    • ss - <ax> - Standard deviation of all voxels

    • svp - <ax> - Volume of all probabilsitic voxels (sum(<in>) x <volume per voxel>)

    • al - <in2> - Average value in <in> for each label in <in2>

    • d - <in2> - Calculate the Dice score between all classes in <in> and <in2>

    • ncc - <in2> - Normalized cross correlation between <in> and <in2>

    • nmi - <in2> - Normalized Mutual Information between <in> and <in2>

    • Vl - <csv> - Volume of each integer label <in>. Save to <csv>file.

    • Nl - <csv> - Count of each label <in>. Save to <csv> file.

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

Optional Inputs:
  • args (a string) – Additional parameters to the command. Maps to a command-line argument: %s.

  • environ (a 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: {})

  • larger_voxel (a float) – Only estimate statistics if voxel is larger than <float>. Maps to a command-line argument: -t %f (position: -3).

  • mask_file (a pathlike object or string representing an existing file) – Statistics within the masked area. Maps to a command-line argument: -m %s (position: -2).

Outputs:

output (an array) – Output array from seg_stats.

StatsCommand

Link to code

Bases: NiftySegCommand

Wrapped executable: seg_stats.

Base Command Interface for seg_stats interfaces.

The executable seg_stats enables the estimation of image statistics on continuous voxel intensities (average, standard deviation, min/max, robust range, percentiles, sum, probabilistic volume, entropy, etc) either over the full image or on a per slice basis (slice axis can be specified), statistics over voxel coordinates (location of max, min and centre of mass, bounding box, etc) and statistics over categorical images (e.g. per region volume, count, average, Dice scores, etc). These statistics are robust to the presence of NaNs, and can be constrained by a mask and/or thresholded at a certain level.

Mandatory Inputs:

in_file (a pathlike object or string representing an existing file) – Image to operate on. Maps to a command-line argument: %s (position: 2).

Optional Inputs:
  • args (a string) – Additional parameters to the command. Maps to a command-line argument: %s.

  • environ (a 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: {})

  • larger_voxel (a float) – Only estimate statistics if voxel is larger than <float>. Maps to a command-line argument: -t %f (position: -3).

  • mask_file (a pathlike object or string representing an existing file) – Statistics within the masked area. Maps to a command-line argument: -m %s (position: -2).

Outputs:

output (an array) – Output array from seg_stats.

UnaryStats

Link to code

Bases: StatsCommand

Wrapped executable: seg_stats.

Unary statistical operations.

See also

Source codeDocumentation

Examples

>>> import copy
>>> from nipype.interfaces import niftyseg
>>> unary = niftyseg.UnaryStats()
>>> unary.inputs.in_file = 'im1.nii'
>>> # Test v operation
>>> unary_v = copy.deepcopy(unary)
>>> unary_v.inputs.operation = 'v'
>>> unary_v.cmdline
'seg_stats im1.nii -v'
>>> unary_v.run()  
>>> # Test vl operation
>>> unary_vl = copy.deepcopy(unary)
>>> unary_vl.inputs.operation = 'vl'
>>> unary_vl.cmdline
'seg_stats im1.nii -vl'
>>> unary_vl.run()  
>>> # Test x operation
>>> unary_x = copy.deepcopy(unary)
>>> unary_x.inputs.operation = 'x'
>>> unary_x.cmdline
'seg_stats im1.nii -x'
>>> unary_x.run()  
Mandatory Inputs:
  • in_file (a pathlike object or string representing an existing file) – Image to operate on. Maps to a command-line argument: %s (position: 2).

  • operation (‘r’ or ‘R’ or ‘a’ or ‘s’ or ‘v’ or ‘vl’ or ‘vp’ or ‘n’ or ‘np’ or ‘e’ or ‘ne’ or ‘x’ or ‘X’ or ‘c’ or ‘B’ or ‘xvox’ or ‘xdim’) –

    Operation to perform:

    • r - The range <min max> of all voxels.

    • R - The robust range (assuming 2% outliers on both sides) of all voxels

    • a - Average of all voxels

    • s - Standard deviation of all voxels

    • v - Volume of all voxels above 0 (<# voxels> * <volume per voxel>)

    • vl - Volume of each integer label (<# voxels per label> x <volume per voxel>)

    • vp - Volume of all probabilsitic voxels (sum(<in>) x <volume per voxel>)

    • n - Count of all voxels above 0 (<# voxels>)

    • np - Sum of all fuzzy voxels (sum(<in>))

    • e - Entropy of all voxels

    • ne - Normalized entropy of all voxels

    • x - Location (i j k x y z) of the smallest value in the image

    • X - Location (i j k x y z) of the largest value in the image

    • c - Location (i j k x y z) of the centre of mass of the object

    • B - Bounding box of all nonzero voxels [ xmin xsize ymin ysize zmin zsize ]

    • xvox - Output the number of voxels in the x direction. Replace x with y/z for other directions.

    • xdim - Output the voxel dimension in the x direction. Replace x with y/z for other directions.

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

Optional Inputs:
  • args (a string) – Additional parameters to the command. Maps to a command-line argument: %s.

  • environ (a 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: {})

  • larger_voxel (a float) – Only estimate statistics if voxel is larger than <float>. Maps to a command-line argument: -t %f (position: -3).

  • mask_file (a pathlike object or string representing an existing file) – Statistics within the masked area. Maps to a command-line argument: -m %s (position: -2).

Outputs:

output (an array) – Output array from seg_stats.