fsl.wrappers.fslmaths

This module provides the fslmaths class, which acts as a wrapper for the fslmaths command-line tool.

class fsl.wrappers.fslmaths.fslmaths(input)[source]

Bases: object

Perform mathematical manipulation of images.

fslmaths is unlike the other FSL wrapper tools in that it provides an object-oriented method-chaining interface, which is hopefully easier to use than constructing a fslmaths command-line call. For example, the following call to the fslmaths wrapper function:

fslmaths('input.nii').thr(0.25).mul(-1).run('output.nii')

will be translated into the following command-line call:

fslmaths input.nii -thr 0.25 -mul -1 output.nii

The fslmaths wrapper function can also be used with in-memory images. If no output file name is passed to the run() method, the result is loaded into memory and returned as a nibabel image. For example:

import nibabel as nib
input  = nib.load('input.nii')
output = fslmaths(input).thr(0.25).mul(-1).run()
__init__(input)[source]

Constructor.

abs()[source]

Absolute value.

bin()[source]

Use (current image>0) to binarise.

binv()[source]

Binarise and invert (binarisation and logical inversion).

recip()[source]

Reciprocal (1/current image).

Tmean()[source]

Mean across time.

Tstd()[source]

Standard deviation across time.

Tmin()[source]

Min across time.

Tmax()[source]

Max across time.

fillh()[source]

fill holes in a binary mask (holes are internal - i.e. do not touch the edge of the FOV).

ero(repeat=1)[source]

Erode by zeroing non-zero voxels when zero voxels in kernel.

dilM(repeat=1)[source]

Mean Dilation of non-zero voxels.

dilF(repeat=1)[source]

Maximum filtering of all voxels.

smooth(sigma)[source]

Spatial smoothing - mean filtering using a gauss kernel of sigma mm

add(image)[source]

Add input to current image.

sub(image)[source]

Subtract image from current image.

mul(image)[source]

Multiply current image by image.

div(image)[source]

Divide current image by image.

mas(image)[source]

Use image (>0) to mask current image.

rem(image)[source]

Divide current image by following image and take remainder.

thr(image)[source]

use image number to threshold current image (zero < image).

uthr(image)[source]

use image number to upper-threshold current image (zero anything above the number).

inm(image)[source]

Intensity normalisation (per 3D volume mean)

bptf(hp_sigma, lp_sigma)[source]

Bandpass temporal filtering; nonlinear highpass and Gaussian linear lowpass (with sigmas in volumes, not seconds); set either sigma<0 to skip that filter.

run(output=None)[source]

Save output of operations to image. Set output to a filename to have the result saved to file, or omit output entirely to have the result returned as a nibabel image.

__run(*cmd)

Run the given fslmaths command.

__dict__ = mappingproxy({'__module__': 'fsl.wrappers.fslmaths', '__doc__': "Perform mathematical manipulation of images.\n\n ``fslmaths`` is unlike the other FSL wrapper tools in that it provides an\n object-oriented method-chaining interface, which is hopefully easier to\n use than constructing a ``fslmaths`` command-line call. For example, the\n following call to the ``fslmaths`` wrapper function::\n\n fslmaths('input.nii').thr(0.25).mul(-1).run('output.nii')\n\n will be translated into the following command-line call::\n\n fslmaths input.nii -thr 0.25 -mul -1 output.nii\n\n The ``fslmaths`` wrapper function can also be used with in-memory\n images. If no output file name is passed to the :meth:`run` method, the\n result is loaded into memory and returned as a ``nibabel`` image. For\n example::\n\n import nibabel as nib\n input = nib.load('input.nii')\n output = fslmaths(input).thr(0.25).mul(-1).run()\n ", '__init__': <function fslmaths.__init__>, 'abs': <function fslmaths.abs>, 'bin': <function fslmaths.bin>, 'binv': <function fslmaths.binv>, 'recip': <function fslmaths.recip>, 'Tmean': <function fslmaths.Tmean>, 'Tstd': <function fslmaths.Tstd>, 'Tmin': <function fslmaths.Tmin>, 'Tmax': <function fslmaths.Tmax>, 'fillh': <function fslmaths.fillh>, 'ero': <function fslmaths.ero>, 'dilM': <function fslmaths.dilM>, 'dilF': <function fslmaths.dilF>, 'smooth': <function fslmaths.smooth>, 'add': <function fslmaths.add>, 'sub': <function fslmaths.sub>, 'mul': <function fslmaths.mul>, 'div': <function fslmaths.div>, 'mas': <function fslmaths.mas>, 'rem': <function fslmaths.rem>, 'thr': <function fslmaths.thr>, 'uthr': <function fslmaths.uthr>, 'inm': <function fslmaths.inm>, 'bptf': <function fslmaths.bptf>, 'run': <function fslmaths.run>, '_fslmaths__run': <function fslmaths.__run>, '__dict__': <attribute '__dict__' of 'fslmaths' objects>, '__weakref__': <attribute '__weakref__' of 'fslmaths' objects>, '__annotations__': {}})
__module__ = 'fsl.wrappers.fslmaths'
__weakref__

list of weak references to the object (if defined)