resample
resample
Resampling and reorientation functions for neuroimaging data.
This module provides functions for resampling and reorienting neuroimaging volumes and vectors to match different spatial configurations.
Functions
| Name | Description |
|---|---|
| reorient | Remap the grid-to-world coordinates mapping of an image. |
| resample | Resample an image to match the space of another image. |
| resample_to | Resample a volume or vector to a target using neuroim2-style names. |
| resample_vec | Resample a 4D NeuroVec to match the space of another image. |
reorient
resample.reorient(x, orient)Remap the grid-to-world coordinates mapping of an image.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| x | NeuroSpace or NeuroVol | The object to reorient | required |
| orient | str or list of str | The orientation code indicating the remapped axes. Can be a 3-letter string like “RAS” or list like [“R”, “A”, “S”] Each position represents: - First: “R” (Right) or “L” (Left) - Second: “A” (Anterior) or “P” (Posterior) - Third: “S” (Superior) or “I” (Inferior) | required |
Returns
| Name | Type | Description |
|---|---|---|
| NeuroSpace or NeuroVol | A reoriented version of x |
Examples
>>> # Reorient a space to RAS
>>> space_ras = reorient(space, "RAS")
>>>
>>> # Or using a list
>>> space_ras = reorient(space, ["R", "A", "S"])resample
resample.resample(source, target, interpolation=3)Resample an image to match the space of another image.
This function resamples a source image to match the spatial properties (dimensions, resolution, and orientation) of a target image or space.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| source | NeuroVol | The source volume to be resampled | required |
| target | NeuroVol or NeuroSpace | The target space to match the dimensions and orientation | required |
| interpolation | int | Type of interpolation to be applied: - 0: nearest neighbor - 1: trilinear - 3: cubic spline (default) | 3 |
Returns
| Name | Type | Description |
|---|---|---|
| DenseNeuroVol | The resampled source image with the same spatial properties as target |
Raises
| Name | Type | Description |
|---|---|---|
| ImportError | If nibabel is not installed | |
| ValueError | If interpolation is not 0, 1, or 3 |
Examples
>>> # Resample to match another volume
>>> resampled = resample(source_vol, target_vol, interpolation=1)
>>>
>>> # Resample to match a specific space
>>> new_space = NeuroSpace(dim=[128, 128, 64], spacing=[2, 2, 2])
>>> resampled = resample(source_vol, new_space)resample_to
resample.resample_to(source, target, method='linear', engine='nibabel')Resample a volume or vector to a target using neuroim2-style names.
resample_vec
resample.resample_vec(source, target, interpolation=3)Resample a 4D NeuroVec to match the space of another image.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| source | NeuroVec | The source 4D vector to be resampled | required |
| target | NeuroVec or NeuroSpace | The target space to match (must be 4D if NeuroSpace) | required |
| interpolation | int | Type of interpolation (0: nearest, 1: linear, 3: cubic) | 3 |
Returns
| Name | Type | Description |
|---|---|---|
| DenseNeuroVec | The resampled source vector |