Resampling
Resampling utilities.
- nitransforms.resampling.SERIALIZE_VOLUME_WINDOW_WIDTH: int = 8
Minimum number of volumes to automatically serialize 4D transforms.
- nitransforms.resampling.apply(transform: TransformBase, spatialimage: str | Path | SpatialImage, reference: str | Path | SpatialImage = None, order: int = 3, mode: str = 'constant', cval: float = 0.0, prefilter: bool = True, output_dtype: dtype = None, dtype_width: int = 8, serialize_nvols: int = 8, max_concurrent: int = 2) SpatialImage | ndarray[source]
Apply a transformation to an image, resampling on the reference spatial object.
- Parameters:
transform (
TransformBase) – The 3D, 3D+t, or 4D transform through which data will be resampled.spatialimage (
SpatialImageoros.PathLike) – The image object containing the data to be resampled in reference spacereference (
SpatialImageoros.PathLike) – 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 (
str, optional) – Determines how the input image is extended when the resamplings overflows a border. One of'constant','reflect','nearest','mirror', or'wrap'. Default is'constant'.cval (
float, optional) – Constant value formode='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 isTrue, which will create a temporary float64 array of filtered values if order > 1. If setting this toFalse, 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, optional) – The dtype of the returned array or image, if specified. IfNone, 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’sget_data_dtype()(on-disk type). Ifreferenceis 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.dtype_width (
int) – Cap the width of the input data type to the given number of bytes. This argument is intended to work as a way to implement lower memory requirements in resampling.serialize_nvols (
int) – Minimum number of volumes in a 3D+t (that is, a series of 3D transformations independent in time) to resample on a one-by-one basis. Serialized resampling can be executed concurrently (parallelized) with the argumentmax_concurrent.max_concurrent (
int) – Maximum number of 3D resamplings to be executed concurrently.
- Returns:
resampled – The data imaged after resampling to reference space.
- Return type:
- nitransforms.resampling.cap_dtype(dt, nbytes)[source]
Cap the datatype size to shave off memory requirements.
Examples
>>> cap_dtype(np.dtype('f8'), 4) dtype('float32')
>>> cap_dtype(np.dtype('f8'), 16) dtype('float64')
>>> cap_dtype('float64', 4) dtype('float32')
>>> cap_dtype(np.dtype('i1'), 4) dtype('int8')
>>> cap_dtype('int8', 4) dtype('int8')
>>> cap_dtype('int32', 1) dtype('int8')
>>> cap_dtype(np.dtype('i8'), 4) dtype('int32')