Resample an Image to Match the Space of Another Image
Source:R/all_generic.R
, R/resample.R
resample-methods.Rd
This function resamples a source image to match the spatial properties (dimensions, resolution, and orientation) of a target image.
This method resamples a NeuroVol object (source
) to match the dimensions and orientation of a NeuroSpace object (target
).
Usage
resample(source, target, ...)
# S4 method for class 'NeuroVol,NeuroVol'
resample(source, target, interpolation = 3L)
# S4 method for class 'NeuroVol,NeuroSpace'
resample(source, target, interpolation = 3L)
Arguments
- source
A NeuroVol object representing the source volume to be resampled.
- target
A NeuroSpace object representing the target space to match the dimensions and orientation of the source volume.
- ...
Additional arguments passed to the resampling function, such as interpolation method, boundary handling, or other resampling options.
- interpolation
A single integer specifying the type of interpolation to be applied to the final resampled image. May be 0 (nearest neighbor), 1 (trilinear), or 3 (cubic spline). No other values are valid.
Value
An object representing the resampled source image, with the same spatial properties as the target image.
A resampled volume in the target space
A NeuroVol object with the resampled source volume matched to the target space's dimensions and orientation.
See also
NeuroVol
for the base volume class
Examples
img <- read_vol(system.file("extdata", "global_mask_v4.nii", package = "neuroim2"))
rspace <- space(img)
### normally, one would resample from two existing soource and target spaces.
### But here we manually create the target space, which is a bit ugly.
newtrans4X3 <- trans(img)[1:4, 1:3]
newtrans4X3 <- newtrans4X3 * c(.5,.5,.5,1)
newtrans <- cbind(newtrans4X3, c(space(img)@origin,1))
rspace <- NeuroSpace(rspace@dim*2, rspace@spacing/2, origin=rspace@origin, trans=trans(img))
if (FALSE) { # \dontrun{
rvol <- resample(img, rspace)
} # }
if (FALSE) { # \dontrun{
# Create source and target volumes
src_vol <- read_vol(system.file("extdata", "example1.nii", package="neuroim2"))
targ_vol <- read_vol(system.file("extdata", "example2.nii", package="neuroim2"))
# Resample source to match target
resampled <- resample(src_vol, targ_vol, interpolation=1)
} # }