Elastix against ANTs, on held-out volumes

NiFreeze registers each volume with ANTs, which reads the images from files on disk and runs as a subprocess, through nipype. Passing the images through the filesystem costs far more time than passing them in memory, and elastix (itk-elastix) takes them from memory, from Python (#590). Elastix’s settings map ANTs’ component by component (Elastix’s settings, mapped from ANTs), and on the volumes those settings were developed on, elastix was ahead of ANTs. This report tests that on volumes neither tool had registered before, in both stages of registration, under rules posted before the run (#672).

The question

Does elastix, with ANTs’ settings mapped directly (#674), register the phantoms’ held-out volumes as accurately as today’s ANTs path, and how fast?

Data

The phantoms (Synthetic reference data)

Sherbrooke (192 volumes at 2 mm) and HCP-YA (270 volumes at 1.25 mm), in the rigid-motion copies at 0.5, 1, 2 and 4 mm and degrees (motion seed 0, no eddy currents, noise 20261029): the copies of Elastix’s settings, mapped from ANTs.

The held-out volumes

The confirmation subset of tools/registration/experiments.py, which the settings’ experiments (#670, #675) never registered: Sherbrooke’s 64 (every third volume, from index 1) and HCP-YA’s 30 (every ninth, from index 4).

The fixed images

Each volume is registered to three (nifreeze.analysis.registration): the noise-free volume at the true position (the oracle), and gqi-krr’s held-out predictions from the unmoved and from the moved data. That makes (64 + 30) × 4 × 3 = 1,128 pairs per stage.

The two arms

ANTs

Today’s path: ANTs 2.4.4 through nipype (AntsRegistration).

Elastix

The direct mapping, with the adaptive stochastic gradient descent, through itk-elastix 0.25.4 (Elastix).

Each arm registers in two stages: the rigid default (b0-to-b0_level0), then the affine second pass (dwi-to-dwi_level1), started from the same arm’s rigid estimate (ANTs takes it through #690). Both arms get the same values (the moving volume’s 12-bit window), one thread and seed 12345. At 1 mm, elastix registers every pair again, in both stages, to check that it repeats.

How the results are judged

The error of a registration is the mean, within the brain mask, of displacements_within_mask() between the estimated and the true fixed-to-moving transform, in mm (The error audit). Time is the wall time of one registration with one thread: ANTs’ includes writing its inputs to files, and elastix’s its preprocessing in Python. A registration that raises counts as failed, with the error of no correction.

Elastix is compared with ANTs in 12 cells (2 protocols × 2 stages × 3 fixed images) with experiments.paired_comparison(), paired by volume and motion and resampled within motions. The margin is 0.01 voxel (0.02 mm on Sherbrooke, 0.0125 mm on HCP-YA), and the interval of the median difference gives “better”, “worse”, “not worse” or “inconclusive”. The working hypothesis (posted on #672) set three rules:

Accurate

In every cell, elastix is “better” or “not worse”; none of its registrations fails; and, in each protocol and stage, it lands further from the truth than no correction no more often than ANTs.

Repeatable

Registered again, elastix returns every estimate bit for bit.

Faster

In each protocol and stage, its median time is below ANTs’.

If all three hold, the estimator takes backends (#667), and elastix becomes its default wherever itk-elastix is installed. The tails (the difference of the 95th percentiles), the comparisons by motion and the maximum errors are reported, but not used in the decision. On the development volumes, the interval of the tail on the prediction from the moved data was 23 to 66 times as wide as the margin, so no tool could have met a rule on it.

Results

Elastix meets all three rules.

Accuracy

Elastix is better than ANTs in 8 of the 12 cells and not worse in the other 4, all four on HCP-YA. The median difference is negative in all 12. In two of HCP-YA’s “not worse” cells (the affine stage, on the oracle and on the prediction from the unmoved data), the whole interval is below zero, but the median is not below the margin, which “better” requires. The cell that was inconclusive on the development volumes (HCP-YA’s rigid stage on the prediction from the moved data) is “not worse” here, with its upper bound just under the margin.

../_images/elastix-accuracy-cells.png

Fig. 16 Elastix minus ANTs, the median difference of the mean error and its 95% interval, in each cell; 1,128 pairs per stage. Points left of zero are cells where elastix lands closer to the truth. “Better” needs the interval below zero and the median left of the margin; “not worse” needs the interval left of the right margin.

Table 33 Elastix minus ANTs, by protocol, stage and fixed image: the median difference of the mean error and the difference of the 95th percentiles (mm), each with its 95% interval, Wilcoxon’s p value Holm-adjusted across the 12 cells, and the verdict.

Protocol

Stage

Fixed image

Elastix - ANTs, median (mm)

95th percentile (mm)

Holm p

Verdict

Sherbrooke (2 mm)

rigid

Oracle

-0.057 [-0.070, -0.047]

-0.128 [-0.194, -0.095]

4e-21

better

Sherbrooke (2 mm)

rigid

Prediction, unmoved data

-0.035 [-0.046, -0.024]

-0.039 [-0.075, -0.001]

1e-08

better

Sherbrooke (2 mm)

rigid

Prediction, moved data

-0.050 [-0.071, -0.029]

-0.023 [-0.324, +0.380]

8e-06

better

Sherbrooke (2 mm)

affine

Oracle

-0.039 [-0.048, -0.030]

-0.037 [-0.050, -0.025]

9e-21

better

Sherbrooke (2 mm)

affine

Prediction, unmoved data

-0.024 [-0.034, -0.019]

-0.082 [-0.113, -0.063]

7e-18

better

Sherbrooke (2 mm)

affine

Prediction, moved data

-0.021 [-0.034, -0.011]

-0.291 [-0.349, +0.118]

6e-05

better

HCP-YA (1.25 mm)

rigid

Oracle

-0.016 [-0.027, -0.010]

-0.025 [-0.063, +0.001]

5e-05

better

HCP-YA (1.25 mm)

rigid

Prediction, unmoved data

-0.021 [-0.025, -0.011]

-0.026 [-0.052, +0.004]

3e-05

better

HCP-YA (1.25 mm)

rigid

Prediction, moved data

-0.001 [-0.017, +0.012]

-0.019 [-0.237, +0.249]

1

not worse

HCP-YA (1.25 mm)

affine

Oracle

-0.008 [-0.013, -0.003]

-0.007 [-0.018, +0.010]

0.001

not worse

HCP-YA (1.25 mm)

affine

Prediction, unmoved data

-0.006 [-0.010, -0.003]

-0.022 [-0.034, -0.006]

0.002

not worse

HCP-YA (1.25 mm)

affine

Prediction, moved data

-0.005 [-0.014, +0.002]

+0.065 [-0.130, +0.372]

1

not worse

Failures and repeatability

No registration failed, in either arm. Of each arm’s 2,256 registrations, ANTs ended further from the truth than no correction twice (both on Sherbrooke, in the rigid stage), and elastix never. Registered again at 1 mm, elastix returned all 564 estimates bit for bit.

Time

Elastix takes 0.58 (Sherbrooke) and 0.64 (HCP-YA) of ANTs’ time in the rigid stage, and 0.39 and 0.31 in the affine stage.

Table 34 Median seconds per registration, with one thread.

Protocol

Stage

ANTs (s)

Elastix (s)

Ratio

Sherbrooke (2 mm)

rigid

1.69

0.98

0.58

Sherbrooke (2 mm)

affine

6.24

2.42

0.39

HCP-YA (1.25 mm)

rigid

5.82

3.70

0.64

HCP-YA (1.25 mm)

affine

32.71

10.07

0.31

Reported, not used in the decision

On the oracle and the prediction from the unmoved data, elastix’s 95th percentile is lower than ANTs’ in all 8 cells, and the interval excludes zero in 5. On the prediction from the moved data, the intervals of the tail are again too wide to tell. Elastix’s median maximum error is below ANTs’ in all 12 cells.

By motion, elastix’s lead comes mostly from the smaller motions. On HCP-YA at 4 mm, the median difference is positive in 3 of 6 cells, each “not worse” or inconclusive on its 30 volumes; on Sherbrooke at 4 mm, it is negative in all 6.

../_images/elastix-accuracy-motion.png

Fig. 17 Elastix minus ANTs, the median difference of the mean error at each motion, with its 95% interval (64 volumes per motion on Sherbrooke, 30 on HCP-YA). The dotted lines are the margin on either side of zero. On the prediction from the moved data, the intervals widen with the motion, as that target’s own error does.

Table 35 Elastix minus ANTs at each motion: the median difference of the mean error (mm) and its verdict on that motion’s volumes.

Protocol

Stage

Fixed image

0.5 mm

1 mm

2 mm

4 mm

Sherbrooke (2 mm)

rigid

Oracle

-0.063, better

-0.065, better

-0.051, better

-0.055, better

Sherbrooke (2 mm)

rigid

Prediction, unmoved data

-0.047, better

-0.049, better

-0.024, not worse

-0.026, not worse

Sherbrooke (2 mm)

rigid

Prediction, moved data

-0.050, better

-0.071, better

-0.036, not worse

-0.043, inconclusive

Sherbrooke (2 mm)

affine

Oracle

-0.070, better

-0.013, not worse

-0.031, better

-0.030, better

Sherbrooke (2 mm)

affine

Prediction, unmoved data

-0.059, better

-0.010, not worse

-0.024, better

-0.019, not worse

Sherbrooke (2 mm)

affine

Prediction, moved data

-0.062, better

-0.006, inconclusive

+0.001, inconclusive

-0.012, inconclusive

HCP-YA (1.25 mm)

rigid

Oracle

-0.032, better

-0.021, better

-0.011, not worse

-0.004, inconclusive

HCP-YA (1.25 mm)

rigid

Prediction, unmoved data

-0.033, better

-0.019, better

-0.021, better

+0.017, inconclusive

HCP-YA (1.25 mm)

rigid

Prediction, moved data

+0.006, inconclusive

+0.021, inconclusive

-0.040, inconclusive

-0.016, inconclusive

HCP-YA (1.25 mm)

affine

Oracle

-0.017, better

-0.009, not worse

-0.005, not worse

+0.002, not worse

HCP-YA (1.25 mm)

affine

Prediction, unmoved data

-0.009, not worse

-0.007, not worse

-0.008, not worse

-0.002, not worse

HCP-YA (1.25 mm)

affine

Prediction, moved data

-0.021, better

-0.005, not worse

+0.005, inconclusive

+0.014, inconclusive

Table 36 Median mean and maximum errors (mm) of each arm.

Protocol

Stage

Fixed image

Mean, ANTs (mm)

Mean, elastix (mm)

Maximum, ANTs (mm)

Maximum, elastix (mm)

Sherbrooke (2 mm)

rigid

Oracle

0.208

0.152

0.378

0.272

Sherbrooke (2 mm)

rigid

Prediction, unmoved data

0.211

0.155

0.382

0.278

Sherbrooke (2 mm)

rigid

Prediction, moved data

0.646

0.581

1.091

1.022

Sherbrooke (2 mm)

affine

Oracle

0.254

0.196

0.560

0.385

Sherbrooke (2 mm)

affine

Prediction, unmoved data

0.279

0.250

0.577

0.470

Sherbrooke (2 mm)

affine

Prediction, moved data

0.703

0.656

1.381

1.300

HCP-YA (1.25 mm)

rigid

Oracle

0.089

0.072

0.152

0.116

HCP-YA (1.25 mm)

rigid

Prediction, unmoved data

0.097

0.075

0.173

0.123

HCP-YA (1.25 mm)

rigid

Prediction, moved data

0.529

0.509

0.915

0.882

HCP-YA (1.25 mm)

affine

Oracle

0.110

0.104

0.241

0.200

HCP-YA (1.25 mm)

affine

Prediction, unmoved data

0.134

0.128

0.279

0.246

HCP-YA (1.25 mm)

affine

Prediction, moved data

0.618

0.618

1.250

1.246

Table 37 For scale: the median mean error (mm) of no correction, at each motion.

Protocol

0.5 mm

1 mm

2 mm

4 mm

Sherbrooke (2 mm)

0.60

1.21

2.42

4.84

HCP-YA (1.25 mm)

0.60

1.20

2.41

4.81

Consequences

  • By the rules of the working hypothesis, the estimator takes backends (#667), and elastix becomes its default wherever itk-elastix is installed. ANTs stays the default without it.

  • Both stages switch: the rigid default and the affine second pass.

Open questions

  • Does elastix’s lead hold beyond the phantoms’ motions? It shrinks with the motion on HCP-YA, and the phantoms stop at 4 mm and 4°. Beyond them only the checks on real images speak (Elastix’s settings, mapped from ANTs), and they were added after the fact: the direct mapping never failed under large rotations of the suite’s b=0 images, and on Stanford HARDI at 4 and 8 mm it ended closer to the truth than ANTs on the prediction from the moved data.

  • The affine second pass was mapped, not tuned.

Deviations from the registration

None from the rules. The rules were set on the development volumes (Elastix’s settings, mapped from ANTs), as the working hypothesis says, and the held-out volumes were registered once.

Reproducing

The run was made outside the phantom dataset, which another branch held at the time, and without a datalad run record. The files it read last changed in the dataset’s commit 6619f01 (2026-10-30), and the dataset stood at the same commit at the start and the end of each protocol. The run’s NiFreeze commit, clean, was 4c1f1344; it took 30 min for Sherbrooke and 64 min for HCP-YA, with 6 workers on 6 physical cores. From the repository’s root:

uv run tools/registration/elastix_accuracy.py --dataset <dataset> \
    --protocol sherbrooke --out <results> --jobs 6
uv run tools/registration/elastix_accuracy.py --dataset <dataset> \
    --protocol hcpya --out <results> --jobs 6

The decision, and the figures and tables of this page, come from:

uv run tools/registration/elastix_accuracy_figures.py --results <results> \
    --out docs/_static/registration/elastix-accuracy --figures