Base

Common interface for transforms.

class nitransforms.base.ImageGrid(image)[source]

Class to represent spaces of gridded data (images).

property affine

Access the indexes-to-RAS affine.

property header

Access the original reference’s header.

index(x)[source]

Get the image array’s indexes corresponding to coordinates.

property inverse

Access the RAS-to-indexes affine.

property ndcoords

List the physical coordinates of this gridded space samples.

property ndindex

List the indexes corresponding to the space grid.

ras(ijk)[source]

Get RAS+ coordinates from input indexes.

class nitransforms.base.SampledSpatialData(dataset)[source]

Represent sampled spatial data: regularly gridded (images) and surfaces.

property ndcoords

List the physical coordinates of this sample.

property ndim

Access the number of dimensions.

property npoints

Access the total number of voxels.

property shape

Access the space’s size of each dimension.

class nitransforms.base.SpatialReference[source]

Factory to create spatial references.

static factory(dataset)[source]

Create a reference for spatial transforms.

class nitransforms.base.TransformBase(reference=None)[source]

Abstract image class to represent transforms.

apply(spatialimage, reference=None, order=3, mode='constant', cval=0.0, prefilter=True, output_dtype=None)[source]

Apply a transformation to an image, resampling on the reference spatial object.

Parameters
  • spatialimage (spatialimage) – The image object containing the data to be resampled in reference space

  • reference (spatial object, optional) – The image, surface, or combination thereof containing the coordinates of samples that will be sampled.

  • order (int, optional) – The order of the spline interpolation, default is 3. The order has to be in the range 0-5.

  • mode ({'constant', 'reflect', 'nearest', 'mirror', 'wrap'}, optional) – Determines how the input image is extended when the resamplings overflows a border. Default is ‘constant’.

  • cval (float, optional) – Constant value for mode='constant'. Default is 0.0.

  • prefilter (bool, optional) – Determines if the image’s data array is prefiltered with a spline filter before interpolation. The default is True, which will create a temporary float64 array of filtered values if order > 1. If setting this to False, the output will be slightly blurred if order > 1, unless the input is prefiltered, i.e. it is the result of calling the spline filter on the original input.

  • output_dtype (dtype specifier, optional) – The dtype of the returned array or image, if specified. If None, the default behavior is to use the effective dtype of the input image. If slope and/or intercept are defined, the effective dtype is float64, otherwise it is equivalent to the input image’s get_data_dtype() (on-disk type). If reference is defined, then the return value is an image, with a data array of the effective dtype but with the on-disk dtype set to the input image’s on-disk dtype.

Returns

resampled – The data imaged after resampling to reference space.

Return type

spatialimage or ndarray

map(x, inverse=False)[source]

Apply \(y = f(x)\).

TransformBase implements the identity transform.

Parameters
  • x (N x D numpy.ndarray) – Input RAS+ coordinates (i.e., physical coordinates).

  • inverse (bool) – If True, apply the inverse transform \(x = f^{-1}(y)\).

Returns

y – Transformed (mapped) RAS+ coordinates (i.e., physical coordinates).

Return type

N x D numpy.ndarray

property ndim

Access the dimensions of the reference space.

property reference

Access a reference space where data will be resampled onto.

to_filename(filename, fmt='X5')[source]

Store the transform in BIDS-Transforms HDF5 file format (.x5).

exception nitransforms.base.TransformError[source]

A custom exception for transforms.