View source: R/imaging-registration-native.R
| register_volume3d | R Documentation |
'rigid', 'affine', or 'SyN')Self-contained image registration for 3D volumes, implemented purely in
RcppEigen (no other external registration library). It mirrors the
core behavior of 'ANTs' antsRegistration: a multi-resolution,
physical-shift scaled gradient-descent optimizer driving a similarity metric,
working entirely in the anatomical RAS (right-anterior-superior)
space. Each volume carries its own vox2ras (0-indexed voxel index to
anatomical RAS) 4\times 4 transform, so volumes with
different sampling, orientation, or field of view are aligned correctly.
register_volume3d(
source,
target,
source_vox2ras = NULL,
target_vox2ras = NULL,
source_mask = NULL,
target_mask = NULL,
source_points = NULL,
target_points = NULL,
points_weight = 0.5,
weights = NULL,
type = c("rigid", "affine", "syn", "syn_only"),
metric = "mattes",
shrink_factors = c(4, 2, 1),
smoothing_sigmas = c(2, 1, 0),
iterations = c(1000, 500, 250),
sampling_rate = 0.2,
interpolation = "trilinear",
number_of_bins = 32L,
seed = 1L,
init_transform = NULL,
syn_iterations = c(40, 20, 0),
syn_sigma = 3,
verbose = TRUE
)
source |
the moving volume to be aligned, a 3D array (for example a
|
target |
the fixed/reference volume to align to, a 3D array (for example
a |
source_vox2ras, target_vox2ras |
4x4 (or 3x4) matrices mapping the
0-indexed voxel coordinate (column-row-slice, |
source_mask, target_mask |
optional 3D mask arrays restricting where the
metric is evaluated; default |
source_points, target_points |
optional |
points_weight |
relative weight of the landmark term against the image
metric in the deformable stage; default |
weights |
optional numeric weights, one per source/target pair,
controlling each channel's contribution to the deformable cost; default is
equal weighting. Weights are normalized internally to sum to 1. Only the
deformable ( |
type |
type of transform to estimate; one of |
metric |
similarity metric: |
shrink_factors |
integer down-sampling factors, one per resolution level
(coarsest first); default |
smoothing_sigmas |
Gaussian smoothing applied at each level, in voxels,
same length as |
iterations |
maximum optimizer iterations per level; default
|
sampling_rate |
fraction of fixed voxels sampled to evaluate the metric
(speeds up large volumes); default |
interpolation |
output interpolation used when warping each modality
onto the target grid: |
number_of_bins |
number of histogram bins for the |
seed |
random seed for the voxel sampler, for reproducibility |
init_transform |
optional 4x4 initial |
syn_iterations, syn_sigma |
deformable stage controls (only used when
|
verbose |
logical; if |
A list with:
transformthe estimated 4x4 RAS-to-RAS linear
transform mapping target (fixed) coordinates to source (moving)
coordinates
imagethe (primary) source resampled onto the
target grid
imagesa list with every source channel resampled onto the
target grid using its own interpolation; image is the
first element. For single-image input this is a length-1 list
forward_field,inverse_field(only for "syn") the
deformation fields
metric_tracethe metric value across optimizer iterations
type,metricechoes of the inputs
apply_transform3d, resample_3d_volume
# --- synthetic same-modality example -------------------------------------
nd <- c(50, 50, 50)
vox2ras <- diag(4); vox2ras[1:3, 4] <- -25
blob <- function(cx, cy, cz, s = 6) {
g <- expand.grid(x = 0:(nd[1]-1), y = 0:(nd[2]-1), z = 0:(nd[3]-1))
array(exp(-((g$x-cx)^2 + (g$y-cy)^2 + (g$z-cz)^2) / (2*s^2)), nd)
}
target <- blob(25, 25, 25)
source <- blob(28, 23, 26) # shifted by a known (3, -2, 1) mm
res <- register_volume3d(
source, target,
source_vox2ras = vox2ras, target_vox2ras = vox2ras,
type = "rigid", metric = "cc"
)
res$transform[1:3, 4] # ~ c(3, -2, 1)
# --- multimodal registration (several co-registered channels) ------------
# Two aligned modalities (e.g. a T1 and a T2) jointly drive the deformable
# stage. Each pair may use its own metric, and `weights` set their relative
# influence (normalized internally to sum to 1). All source channels must
# share a grid; likewise all target channels.
t1_target <- blob(25, 25, 25, s = 6)
t2_target <- blob(25, 25, 25, s = 9) # same anatomy, different contrast
t1_source <- blob(27, 24, 26, s = 6) # both channels share the same warp
t2_source <- blob(27, 24, 26, s = 9)
res_mm <- register_volume3d(
source = list(t1_source, t2_source),
target = list(t1_target, t2_target),
source_vox2ras = vox2ras, target_vox2ras = vox2ras,
weights = c(2, 1), # T1 counts twice as much as T2
metric = c("mattes", "cc"), # one metric per channel
type = "syn"
)
res_mm$transform[1:3, 4]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.