Skip to content

feat(np_utils): Voronoi / nearest-label expansion - #147

Open
Hendrik-code wants to merge 1 commit into
mainfrom
feat/np-voronoi-labels
Open

feat(np_utils): Voronoi / nearest-label expansion#147
Hendrik-code wants to merge 1 commit into
mainfrom
feat/np-voronoi-labels

Conversation

@Hendrik-code

@Hendrik-code Hendrik-code commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Upstreams the nearest-label partition from voronoi-loss's make_voronoi_arr, using panoptica's
algorithm (Apache-2.0, panoptica/_functionals.py::_get_voronoi_regions) instead of its
implementation.

What's new

np_voronoi_labels(arr, label_ref, max_distance, zoom, signed_background, tie_to_zero) assigns every
voxel the label of the nearest labelled region, keeping voronoi-loss's semantics:

  • labelled voxels keep their positive label,
  • background voxels carry the negated label of the region they were assigned to, so the original
    mask is still recoverable from the result,
  • voxels exactly equidistant to two different regions are set to 0 rather than broken arbitrarily.
>>> arr = np.zeros((5, 1, 1), dtype=np.uint8); arr[0] = 1; arr[4] = 2
>>> np_voronoi_labels(arr).ravel().tolist()
[1, -1, 0, -2, 2]

np_expand_labels(arr, distance, ...) is the plain unsigned form — the unbounded, spacing-aware
sibling of the existing np_dilate_msk_euclid.

Why the rewrite

voronoi-loss ran one full-array distance transform per labelO(n_labels · n_voxels) — and
needed a Ray cluster with an object store and a /tmp/spill directory to make that tractable. The
whole partition falls out of a single Euclidean feature transform of the background instead, since
the nearest background voxel of arr == 0 is exactly the nearest labelled voxel of arr.

volume np_voronoi_labels voronoi-loss loop (serial, no Ray)
128³, 150 labels 1.9 s 55.8 s
256×256×128, 300 labels 7.5 s 426.1 s

Both outputs are voxel-identical.

Unlike the original, the cost does not grow with the label count at all.

Recovering the ties

The equidistant voxels came for free from the original's per-label loop; distance_transform_edt
picks one nearest source and never reports that the choice was arbitrary, so they have to be found
afterwards. _np_voronoi_ties restricts the search to voxels next to a change in the nearest-label
assignment, then tests each of their neighbours' nearest sources for being at exactly the same
distance. Any neighbour's source is a real foreground voxel, so a hit is always a genuine tie — the
test can miss one, but never invent one. In practice it is exact.

Additions on top of the original

label_ref to partition by a subset of labels, max_distance to leave far background voxels empty,
zoom for anisotropic voxel spacing, and flags to turn the signing and the tie handling off.

Tests

16 tests in unit_tests/test_nputils.py, including a per-voxel brute-force reference (isotropic and
anisotropic, 2D and 3D). The output is also voxel-identical to voronoi-loss's original loop on random
2D and 3D masks — verified locally, not committed, since reproducing it needs that repo.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GFZf44LHBB6N5jaf6YFzhx

Upstreams the nearest-label partition from voronoi-loss's make_voronoi_arr,
keeping its semantics: labelled voxels keep their positive label, background
voxels carry the negated label of the region they were assigned to, and voxels
exactly equidistant to two different regions are set to 0 instead of being
broken arbitrarily.

The algorithm is panoptica's (Apache-2.0, panoptica/_functionals.py
_get_voronoi_regions): a single Euclidean feature transform of the background,
since the nearest background voxel of `arr == 0` is exactly the nearest
labelled voxel of `arr`. voronoi-loss instead ran one full-array distance
transform per label and needed a Ray cluster and a spill directory to make that
tractable. On a 128^3 volume with 150 labels this is 1.9s against 55.8s for the
original loop on one core, and unlike the original the cost does not grow with
the label count.

The equidistant voxels the original got for free from its per-label loop have
to be recovered afterwards, because distance_transform_edt picks one nearest
source and never reports that the choice was arbitrary. _np_voronoi_ties finds
them by restricting to voxels next to a change in the assignment and testing
each of their neighbours' nearest sources for being at exactly the same
distance. Any such source is a real foreground voxel, so a hit is always a
genuine tie - the test can miss one, but never invent one. In practice it is
exact: the result is voxel-identical to the original on random 2D and 3D masks,
and to a brute-force per-voxel reference.

Added on top of the original: label_ref to partition by a subset, max_distance
to leave far background voxels empty, zoom for anisotropic spacing, and flags
to turn off the signing and the tie handling. np_expand_labels is that plain
form, the unbounded and spacing-aware sibling of np_dilate_msk_euclid.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GFZf44LHBB6N5jaf6YFzhx
@github-actions

Copy link
Copy Markdown

Benchmark comparison

Speed (wall time per call)

baseline a4af9d7 vs head a4af9d7 · python 3.11.16 · 5 repeats + 1 warmup

Showing the 5 most-changed measurements per case; the rest are collapsed. Rows with a baseline below 3 ms are tagged (noise) — runner jitter on those swamps any real change.

ct_3d — shape (73, 47, 73)

Measurement baseline ms (median ±½·range) head ms (median ±½·range) Δ % p
nii_filter_connected_components 4.35 ±0.15 4.10 ±0.13 -5.7% 0.017
nii_fill_holes 4.49 ±0.11 4.71 ±0.40 +4.9% 0.169
poi_calc_centroids_nocrop 5.28 ±0.11 5.43 ±0.29 +2.7% 0.482
nii_save 10.25 ±0.37 10.47 ±0.20 +2.1% 0.055
poi_calc_poi_from_subreg_vert 10.51 ±0.47 10.70 ±0.08 +1.9% 0.140
… 31 more measurements
Measurement baseline ms (median ±½·range) head ms (median ±½·range) Δ % p
nii_rescale 43.72 ±1.22 44.35 ±1.02 +1.4% 0.191
nii_resample_from_to 46.10 ±2.22 45.74 ±1.35 -0.8% 0.527
nii_load_img 12.66 ±0.18 12.73 ±0.13 +0.6% 0.885
nii_erode_msk 5.94 ±0.09 5.96 ±0.37 +0.4% 0.902
nii_dilate_msk 98.95 ±1.83 98.89 ±0.37 -0.1% 0.742
metric_voxels 250463.00 ±0.00 250463.00 ±0.00 +0.0%
metric_labels 3.00 ±0.00 3.00 ±0.00 +0.0%
metric_foreground_pct 14.51 ±0.00 14.51 ±0.00 +0.0%
nii_get_array 0.05 ±0.00 0.07 ±0.00 +36.0% (noise) 0.000
poi_to_global 0.20 ±0.01 0.24 ±0.02 +24.7% (noise) 0.000
poi_rescale 0.19 ±0.02 0.23 ±0.01 +20.6% (noise) 0.002
poi_map_labels 0.20 ±0.01 0.17 ±0.01 -15.6% (noise) 0.005
nii_apply_crop 0.68 ±0.04 0.58 ±0.02 -14.7% (noise) 0.001
nii_extract_label 0.42 ±0.02 0.36 ±0.02 -14.1% (noise) 0.002
poi_resample_from_to 0.66 ±0.04 0.58 ±0.04 -12.5% (noise) 0.013
nii_set_dtype 0.50 ±0.03 0.56 ±0.03 +11.8% (noise) 0.041
poi_reorient 0.37 ±0.03 0.41 ±0.02 +9.8% (noise) 0.034
poi_local_to_global_arr 0.31 ±0.02 0.29 ±0.01 -6.7% (noise) 0.210
poi_save 0.39 ±0.02 0.41 ±0.03 +5.3% (noise) 0.319
nii_map_labels 1.12 ±0.03 1.06 ±0.03 -4.7% (noise) 0.065
nii_reorient 0.69 ±0.03 0.67 ±0.02 -3.0% (noise) 0.090
nii_compute_crop 0.33 ±0.02 0.32 ±0.03 -2.5% (noise) 0.282
nii_center_of_masses 1.54 ±0.02 1.52 ±0.07 -1.2% (noise) 0.299
poi_load 0.84 ±0.03 0.85 ±0.02 +1.2% (noise) 0.709
nii_volumes 1.63 ±0.06 1.65 ±0.04 +1.0% (noise) 0.909
nii_pad_to 0.71 ±0.34 0.70 ±0.04 -1.0% (noise) 0.351
nii_get_connected_components 2.39 ±0.11 2.37 ±0.09 -0.8% (noise) 0.545
nii_rescale_seg 2.83 ±0.05 2.82 ±0.04 -0.4% (noise) 0.614
nii_unique 0.91 ±0.06 0.91 ±0.04 +0.3% (noise) 0.315
poi_calc_centroids 2.02 ±0.08 2.01 ±0.06 -0.3% (noise) 0.966
nii_load_seg 2.45 ±0.09 2.45 ±0.05 -0.1% (noise) 0.786

ct_2d — shape (73, 47, 1)

Measurement baseline ms (median ±½·range) head ms (median ±½·range) Δ % p
nii_resample_from_to 6.71 ±0.13 6.96 ±0.25 +3.6% 0.094
nii_dilate_msk 11.42 ±0.26 11.76 ±0.43 +3.0% 0.273
nii_rescale 5.31 ±0.12 5.38 ±0.10 +1.3% 0.637
metric_voxels 3431.00 ±0.00 3431.00 ±0.00 +0.0%
metric_labels 3.00 ±0.00 3.00 ±0.00 +0.0%
… 30 more measurements
Measurement baseline ms (median ±½·range) head ms (median ±½·range) Δ % p
metric_foreground_pct 37.60 ±0.00 37.60 ±0.00 +0.0%
nii_reorient 0.69 ±0.07 0.78 ±0.01 +12.6% (noise) 0.044
poi_local_to_global_arr 0.36 ±0.01 0.32 ±0.02 -11.0% (noise) 0.004
nii_get_connected_components 0.65 ±0.03 0.70 ±0.06 +7.3% (noise) 0.169
nii_center_of_masses 0.21 ±0.01 0.22 ±0.01 +7.2% (noise) 0.004
nii_extract_label 0.41 ±0.03 0.44 ±0.01 +6.4% (noise) 0.278
poi_load 0.91 ±0.02 0.86 ±0.03 -5.6% (noise) 0.005
poi_resample_from_to 0.65 ±0.03 0.69 ±0.03 +5.4% (noise) 0.089
nii_map_labels 0.50 ±0.01 0.52 ±0.01 +4.5% (noise) 0.011
poi_rescale 0.27 ±0.01 0.25 ±0.01 -4.4% (noise) 0.110
nii_get_array 0.02 ±0.00 0.02 ±0.00 +4.3% (noise) 0.034
nii_load_seg 1.38 ±0.04 1.44 ±0.02 +4.3% (noise) 0.108
nii_pad_to 0.56 ±0.07 0.58 ±0.02 +4.1% (noise) 0.967
nii_volumes 0.31 ±0.01 0.30 ±0.01 -3.7% (noise) 0.171
poi_reorient 0.47 ±0.02 0.45 ±0.02 -3.6% (noise) 0.468
nii_rescale_seg 0.76 ±0.01 0.78 ±0.03 +3.4% (noise) 0.369
nii_load_img 1.38 ±0.02 1.34 ±0.02 -3.0% (noise) 0.006
nii_compute_crop 0.16 ±0.01 0.17 ±0.01 +3.0% (noise) 0.048
nii_unique 0.15 ±0.01 0.15 ±0.00 +2.2% (noise) 0.763
nii_filter_connected_components 0.82 ±0.02 0.84 ±0.02 +2.1% (noise) 0.097
nii_apply_crop 0.67 ±0.01 0.66 ±0.03 -1.9% (noise) 0.296
nii_set_dtype 0.43 ±0.01 0.44 ±0.02 +1.3% (noise) 0.651
nii_erode_msk 0.91 ±0.03 0.90 ±0.02 -1.1% (noise) 0.532
poi_save 0.49 ±0.03 0.50 ±0.02 +1.1% (noise) 0.778
nii_fill_holes 0.79 ±0.01 0.80 ±0.05 +1.0% (noise) 0.760
poi_calc_centroids_nocrop 1.06 ±0.02 1.07 ±0.03 +0.9% (noise) 0.475
poi_map_labels 0.22 ±0.01 0.22 ±0.00 -0.2% (noise) 0.454
poi_calc_centroids 0.86 ±0.03 0.86 ±0.02 -0.1% (noise) 0.869
nii_save 1.26 ±0.07 1.26 ±0.03 -0.1% (noise) 0.533
poi_to_global 0.26 ±0.02 0.26 ±0.01 -0.0% (noise) 0.753

mri_3d — shape (68, 52, 67)

Measurement baseline ms (median ±½·range) head ms (median ±½·range) Δ % p
poi_calc_centroids_nocrop 11.66 ±0.38 10.87 ±0.25 -6.7% 0.019
nii_load_img 10.06 ±0.10 10.23 ±0.13 +1.7% 0.084
nii_dilate_msk 128.48 ±0.46 130.35 ±1.58 +1.5% 0.031
nii_erode_msk 7.76 ±0.26 7.86 ±0.09 +1.3% 0.360
nii_fill_holes 5.82 ±0.27 5.89 ±0.31 +1.3% 0.674
… 31 more measurements
Measurement baseline ms (median ±½·range) head ms (median ±½·range) Δ % p
nii_rescale 41.05 ±1.66 41.37 ±0.57 +0.8% 0.648
nii_filter_connected_components 4.69 ±0.11 4.72 ±0.10 +0.7% 0.836
poi_calc_poi_from_subreg_vert 9.59 ±0.16 9.65 ±0.12 +0.7% 0.782
nii_resample_from_to 42.42 ±0.93 42.58 ±0.41 +0.4% 1.000
nii_save 8.64 ±0.12 8.61 ±0.14 -0.4% 0.810
metric_voxels 236912.00 ±0.00 236912.00 ±0.00 +0.0%
metric_labels 8.00 ±0.00 8.00 ±0.00 +0.0%
metric_foreground_pct 18.21 ±0.00 18.21 ±0.00 +0.0%
nii_extract_label 0.50 ±0.01 0.54 ±0.02 +9.3% (noise) 0.003
nii_pad_to 0.81 ±0.04 0.76 ±0.03 -6.3% (noise) 0.017
poi_to_global 0.28 ±0.02 0.29 ±0.01 +6.2% (noise) 0.171
nii_center_of_masses 1.77 ±0.04 1.84 ±0.13 +4.0% (noise) 0.171
nii_unique 0.97 ±0.02 1.01 ±0.05 +3.4% (noise) 0.387
nii_map_labels 1.25 ±0.04 1.28 ±0.02 +2.9% (noise) 0.025
nii_compute_crop 0.37 ±0.02 0.38 ±0.02 +2.7% (noise) 0.958
nii_get_array 0.08 ±0.01 0.08 ±0.00 +2.6% (noise) 0.686
nii_reorient 0.85 ±0.03 0.83 ±0.02 -2.0% (noise) 0.164
poi_map_labels 0.27 ±0.00 0.26 ±0.01 -1.8% (noise) 0.194
poi_rescale 0.30 ±0.01 0.31 ±0.03 +1.7% (noise) 0.490
poi_save 0.54 ±0.02 0.54 ±0.02 +1.5% (noise) 0.507
nii_load_seg 2.55 ±0.11 2.58 ±0.12 +1.5% (noise) 0.924
nii_set_dtype 0.65 ±0.02 0.66 ±0.04 +1.5% (noise) 0.779
nii_rescale_seg 2.75 ±0.06 2.79 ±0.08 +1.2% (noise) 0.315
poi_local_to_global_arr 0.35 ±0.01 0.36 ±0.02 +1.1% (noise) 0.283
poi_reorient 0.48 ±0.02 0.49 ±0.04 +1.1% (noise) 0.935
nii_volumes 1.75 ±0.02 1.76 ±0.07 +0.8% (noise) 0.736
poi_calc_centroids 2.50 ±0.06 2.48 ±0.04 -0.7% (noise) 0.612
poi_load 1.84 ±0.03 1.85 ±0.04 +0.5% (noise) 0.485
nii_get_connected_components 2.70 ±0.08 2.70 ±0.04 +0.2% (noise) 0.633
poi_resample_from_to 0.75 ±0.02 0.75 ±0.03 +0.1% (noise) 0.818
nii_apply_crop 0.72 ±0.03 0.72 ±0.01 -0.1% (noise) 0.415

mri_2d — shape (68, 52, 1)

Measurement baseline ms (median ±½·range) head ms (median ±½·range) Δ % p
nii_dilate_msk 15.00 ±0.11 15.56 ±0.17 +3.7% 0.001
nii_resample_from_to 6.76 ±0.12 6.79 ±0.25 +0.4% 0.914
nii_rescale 5.32 ±0.13 5.32 ±0.08 +0.1% 0.975
metric_voxels 3536.00 ±0.00 3536.00 ±0.00 +0.0%
metric_labels 7.00 ±0.00 7.00 ±0.00 +0.0%
… 30 more measurements
Measurement baseline ms (median ±½·range) head ms (median ±½·range) Δ % p
metric_foreground_pct 50.17 ±0.00 50.17 ±0.00 +0.0%
nii_get_array 0.02 ±0.00 0.02 ±0.00 -14.3% (noise) 0.411
poi_save 0.52 ±0.01 0.48 ±0.04 -7.9% (noise) 0.428
poi_to_global 0.28 ±0.01 0.30 ±0.02 +7.7% (noise) 0.083
nii_set_dtype 0.40 ±0.03 0.43 ±0.01 +7.2% (noise) 0.028
nii_load_img 1.26 ±0.07 1.34 ±0.09 +6.5% (noise) 0.239
nii_fill_holes 0.91 ±0.04 0.95 ±0.03 +4.7% (noise) 0.114
poi_local_to_global_arr 0.34 ±0.02 0.32 ±0.01 -4.6% (noise) 0.698
nii_extract_label 0.43 ±0.01 0.41 ±0.02 -3.9% (noise) 0.488
nii_center_of_masses 0.39 ±0.02 0.40 ±0.01 +3.9% (noise) 0.096
nii_rescale_seg 0.74 ±0.01 0.77 ±0.06 +3.7% (noise) 0.715
poi_reorient 0.46 ±0.02 0.48 ±0.01 +3.6% (noise) 0.084
nii_pad_to 0.57 ±0.03 0.59 ±0.02 +3.5% (noise) 0.639
nii_compute_crop 0.16 ±0.01 0.16 ±0.01 +3.0% (noise) 0.575
nii_load_seg 1.45 ±0.02 1.49 ±0.05 +3.0% (noise) 0.139
nii_unique 0.14 ±0.01 0.15 ±0.01 +3.0% (noise) 0.601
poi_calc_centroids 1.03 ±0.07 1.06 ±0.01 +2.9% (noise) 0.535
nii_filter_connected_components 0.80 ±0.02 0.78 ±0.03 -2.7% (noise) 0.945
nii_get_connected_components 0.63 ±0.02 0.65 ±0.03 +2.7% (noise) 0.288
poi_calc_centroids_nocrop 1.24 ±0.03 1.21 ±0.02 -2.3% (noise) 0.650
nii_erode_msk 1.07 ±0.04 1.10 ±0.05 +2.2% (noise) 0.412
nii_map_labels 0.50 ±0.03 0.51 ±0.01 +2.1% (noise) 0.462
nii_apply_crop 0.66 ±0.01 0.67 ±0.01 +1.9% (noise) 0.415
poi_rescale 0.29 ±0.01 0.29 ±0.01 -1.6% (noise) 0.689
nii_save 1.26 ±0.05 1.24 ±0.04 -1.6% (noise) 0.281
nii_volumes 0.44 ±0.01 0.45 ±0.02 +1.4% (noise) 0.381
poi_map_labels 0.25 ±0.01 0.25 ±0.01 +1.1% (noise) 0.498
poi_resample_from_to 0.73 ±0.02 0.73 ±0.02 -0.8% (noise) 0.287
poi_load 1.68 ±0.02 1.69 ±0.02 +0.8% (noise) 0.175
nii_reorient 0.80 ±0.03 0.80 ±0.03 -0.2% (noise) 0.240

Gate: a measurement fails when the baseline is ≥ 1 ms, the median grows by ≥ 50%, and Welch's t-test gives p < 0.05. metric_* rows are context only.

Memory (peak RSS growth per call)

baseline a4af9d7 vs head a4af9d7 · python 3.11.16 · 5 repeats + 1 warmup · sampler proc-status, isolation fork · measurement floor ≈ 0.90 MiB

Showing the 5 most-changed measurements per case; the rest are collapsed. Rows with a baseline below 3 MiB are tagged (noise) — runner jitter on those swamps any real change.

ct_3d — shape (73, 47, 73)

Measurement baseline MiB (median ±½·range) head MiB (median ±½·range) Δ % p
nii_erode_msk 6.05 ±0.00 6.06 ±0.00 +0.2%
nii_rescale_seg 6.20 ±0.00 6.19 ±0.00 -0.1%
nii_rescale 6.42 ±0.00 6.42 ±0.00 -0.1%
nii_load_img 3.56 ±0.00 3.56 ±0.00 +0.0%
nii_load_seg 6.07 ±0.00 6.07 ±0.00 +0.0%
… 31 more measurements
Measurement baseline MiB (median ±½·range) head MiB (median ±½·range) Δ % p
nii_save 3.84 ±0.00 3.84 ±0.00 +0.0%
nii_set_dtype 5.37 ±0.00 5.37 ±0.00 +0.0%
nii_reorient 5.97 ±0.00 5.97 ±0.00 +0.0%
nii_resample_from_to 6.55 ±0.00 6.55 ±0.00 +0.0%
nii_apply_crop 5.93 ±0.00 5.93 ±0.00 +0.0%
nii_pad_to 5.49 ±0.00 5.49 ±0.00 +0.0%
nii_volumes 3.52 ±0.00 3.52 ±0.00 +0.0%
nii_center_of_masses 3.21 ±0.00 3.21 ±0.00 +0.0%
nii_extract_label 5.49 ±0.00 5.49 ±0.00 +0.0%
nii_map_labels 5.55 ±0.00 5.55 ±0.00 +0.0%
nii_dilate_msk 6.05 ±0.00 6.05 ±0.00 +0.0%
nii_fill_holes 6.41 ±0.00 6.41 ±0.00 +0.0%
nii_get_connected_components 6.68 ±0.00 6.68 ±0.00 +0.0%
nii_filter_connected_components 6.99 ±0.00 6.99 ±0.00 +0.0%
poi_calc_centroids 6.18 ±0.00 6.18 ±0.00 +0.0%
poi_calc_centroids_nocrop 6.05 ±0.00 6.05 ±0.00 +0.0%
poi_reorient 3.89 ±0.00 3.89 ±0.00 +0.0%
poi_to_global 3.14 ±0.00 3.14 ±0.00 +0.0%
poi_local_to_global_arr 3.02 ±0.00 3.02 ±0.00 +0.0%
poi_resample_from_to 5.53 ±0.00 5.53 ±0.00 +0.0%
poi_calc_poi_from_subreg_vert 7.30 ±0.00 7.30 ±0.00 +0.0%
metric_voxels 250463.00 ±0.00 250463.00 ±0.00 +0.0%
metric_labels 3.00 ±0.00 3.00 ±0.00 +0.0%
metric_foreground_pct 14.51 ±0.00 14.51 ±0.00 +0.0%
nii_get_array 1.65 ±0.00 1.65 ±0.00 +0.0% (noise)
nii_compute_crop 2.96 ±0.00 2.96 ±0.00 +0.0% (noise)
nii_unique 2.90 ±0.00 2.90 ±0.00 +0.0% (noise)
poi_rescale 2.61 ±0.00 2.61 ±0.00 +0.0% (noise)
poi_save 1.46 ±0.00 1.46 ±0.00 +0.0% (noise)
poi_map_labels 1.77 ±0.00 1.77 ±0.00 +0.0% (noise)
poi_load 1.61 ±0.00 1.61 ±0.00 +0.0% (noise)

ct_2d — shape (73, 47, 1)

Measurement baseline MiB (median ±½·range) head MiB (median ±½·range) Δ % p
nii_erode_msk 5.98 ±0.00 6.00 ±0.00 +0.2%
nii_rescale_seg 6.13 ±0.00 6.13 ±0.00 -0.1%
nii_rescale 6.36 ±0.00 6.36 ±0.00 -0.1%
nii_load_img 3.50 ±0.00 3.50 ±0.00 +0.0%
nii_load_seg 6.01 ±0.00 6.01 ±0.00 +0.0%
… 30 more measurements
Measurement baseline MiB (median ±½·range) head MiB (median ±½·range) Δ % p
nii_save 3.77 ±0.00 3.77 ±0.00 +0.0%
nii_set_dtype 5.30 ±0.00 5.30 ±0.00 +0.0%
nii_reorient 5.91 ±0.00 5.91 ±0.00 +0.0%
nii_resample_from_to 6.48 ±0.00 6.48 ±0.00 +0.0%
nii_apply_crop 5.87 ±0.00 5.87 ±0.00 +0.0%
nii_pad_to 5.43 ±0.00 5.43 ±0.00 +0.0%
nii_volumes 3.46 ±0.00 3.46 ±0.00 +0.0%
nii_center_of_masses 3.15 ±0.00 3.15 ±0.00 +0.0%
nii_extract_label 5.43 ±0.00 5.43 ±0.00 +0.0%
nii_map_labels 5.49 ±0.00 5.49 ±0.00 +0.0%
nii_dilate_msk 5.99 ±0.00 5.99 ±0.00 +0.0%
nii_fill_holes 6.34 ±0.00 6.34 ±0.00 +0.0%
nii_get_connected_components 6.62 ±0.00 6.62 ±0.00 +0.0%
nii_filter_connected_components 6.93 ±0.00 6.93 ±0.00 +0.0%
poi_calc_centroids 6.12 ±0.00 6.12 ±0.00 +0.0%
poi_calc_centroids_nocrop 6.05 ±0.00 6.05 ±0.00 +0.0%
poi_reorient 3.83 ±0.00 3.83 ±0.00 +0.0%
poi_to_global 3.08 ±0.00 3.08 ±0.00 +0.0%
poi_resample_from_to 5.46 ±0.00 5.46 ±0.00 +0.0%
metric_voxels 3431.00 ±0.00 3431.00 ±0.00 +0.0%
metric_labels 3.00 ±0.00 3.00 ±0.00 +0.0%
metric_foreground_pct 37.60 ±0.00 37.60 ±0.00 +0.0%
nii_get_array 1.59 ±0.00 1.59 ±0.00 +0.0% (noise)
nii_compute_crop 2.90 ±0.00 2.90 ±0.00 +0.0% (noise)
nii_unique 2.84 ±0.00 2.84 ±0.00 +0.0% (noise)
poi_rescale 2.54 ±0.00 2.54 ±0.00 +0.0% (noise)
poi_local_to_global_arr 2.96 ±0.00 2.96 ±0.00 +0.0% (noise)
poi_save 1.40 ±0.00 1.40 ±0.00 +0.0% (noise)
poi_map_labels 1.71 ±0.00 1.71 ±0.00 +0.0% (noise)
poi_load 1.55 ±0.00 1.55 ±0.00 +0.0% (noise)

mri_3d — shape (68, 52, 67)

Measurement baseline MiB (median ±½·range) head MiB (median ±½·range) Δ % p
nii_erode_msk 5.98 ±0.00 6.00 ±0.00 +0.2%
nii_rescale_seg 6.13 ±0.00 6.13 ±0.00 -0.1%
nii_rescale 6.36 ±0.00 6.36 ±0.00 -0.1%
nii_load_img 3.56 ±0.00 3.56 ±0.00 +0.0%
nii_load_seg 6.01 ±0.00 6.01 ±0.00 +0.0%
… 31 more measurements
Measurement baseline MiB (median ±½·range) head MiB (median ±½·range) Δ % p
nii_save 3.77 ±0.00 3.77 ±0.00 +0.0%
nii_set_dtype 5.37 ±0.00 5.37 ±0.00 +0.0%
nii_reorient 5.91 ±0.00 5.91 ±0.00 +0.0%
nii_resample_from_to 6.48 ±0.00 6.48 ±0.00 +0.0%
nii_apply_crop 5.87 ±0.00 5.87 ±0.00 +0.0%
nii_pad_to 5.43 ±0.00 5.43 ±0.00 +0.0%
nii_volumes 3.46 ±0.00 3.46 ±0.00 +0.0%
nii_center_of_masses 3.15 ±0.00 3.15 ±0.00 +0.0%
nii_extract_label 5.43 ±0.00 5.43 ±0.00 +0.0%
nii_map_labels 5.49 ±0.00 5.49 ±0.00 +0.0%
nii_dilate_msk 5.99 ±0.00 5.99 ±0.00 +0.0%
nii_fill_holes 6.34 ±0.00 6.34 ±0.00 +0.0%
nii_get_connected_components 6.62 ±0.00 6.62 ±0.00 +0.0%
nii_filter_connected_components 6.93 ±0.00 6.93 ±0.00 +0.0%
poi_calc_centroids 6.12 ±0.00 6.12 ±0.00 +0.0%
poi_calc_centroids_nocrop 5.99 ±0.00 5.99 ±0.00 +0.0%
poi_reorient 3.83 ±0.00 3.83 ±0.00 +0.0%
poi_to_global 3.08 ±0.00 3.08 ±0.00 +0.0%
poi_resample_from_to 5.46 ±0.00 5.46 ±0.00 +0.0%
poi_calc_poi_from_subreg_vert 7.30 ±0.00 7.30 ±0.00 +0.0%
metric_voxels 236912.00 ±0.00 236912.00 ±0.00 +0.0%
metric_labels 8.00 ±0.00 8.00 ±0.00 +0.0%
metric_foreground_pct 18.21 ±0.00 18.21 ±0.00 +0.0%
nii_get_array 1.59 ±0.00 1.59 ±0.00 +0.0% (noise)
nii_compute_crop 2.90 ±0.00 2.90 ±0.00 +0.0% (noise)
nii_unique 2.84 ±0.00 2.84 ±0.00 +0.0% (noise)
poi_rescale 2.54 ±0.00 2.54 ±0.00 +0.0% (noise)
poi_local_to_global_arr 2.96 ±0.00 2.96 ±0.00 +0.0% (noise)
poi_save 1.46 ±0.00 1.46 ±0.00 +0.0% (noise)
poi_map_labels 1.71 ±0.00 1.71 ±0.00 +0.0% (noise)
poi_load 1.55 ±0.00 1.55 ±0.00 +0.0% (noise)

mri_2d — shape (68, 52, 1)

Measurement baseline MiB (median ±½·range) head MiB (median ±½·range) Δ % p
nii_erode_msk 5.98 ±0.00 6.00 ±0.00 +0.2%
nii_rescale_seg 6.13 ±0.00 6.13 ±0.00 -0.1%
nii_rescale 6.36 ±0.00 6.36 ±0.00 -0.1%
nii_load_img 3.56 ±0.00 3.56 ±0.00 +0.0%
nii_load_seg 6.01 ±0.00 6.01 ±0.00 +0.0%
… 30 more measurements
Measurement baseline MiB (median ±½·range) head MiB (median ±½·range) Δ % p
nii_save 3.77 ±0.00 3.77 ±0.00 +0.0%
nii_set_dtype 5.37 ±0.00 5.37 ±0.00 +0.0%
nii_reorient 5.91 ±0.00 5.91 ±0.00 +0.0%
nii_resample_from_to 6.48 ±0.00 6.48 ±0.00 +0.0%
nii_apply_crop 5.87 ±0.00 5.87 ±0.00 +0.0%
nii_pad_to 5.43 ±0.00 5.43 ±0.00 +0.0%
nii_volumes 3.46 ±0.00 3.46 ±0.00 +0.0%
nii_center_of_masses 3.15 ±0.00 3.15 ±0.00 +0.0%
nii_extract_label 5.43 ±0.00 5.43 ±0.00 +0.0%
nii_map_labels 5.49 ±0.00 5.49 ±0.00 +0.0%
nii_dilate_msk 5.99 ±0.00 5.99 ±0.00 +0.0%
nii_fill_holes 6.34 ±0.00 6.34 ±0.00 +0.0%
nii_get_connected_components 6.62 ±0.00 6.62 ±0.00 +0.0%
nii_filter_connected_components 6.93 ±0.00 6.93 ±0.00 +0.0%
poi_calc_centroids 6.12 ±0.00 6.12 ±0.00 +0.0%
poi_calc_centroids_nocrop 6.05 ±0.00 6.05 ±0.00 +0.0%
poi_reorient 3.83 ±0.00 3.83 ±0.00 +0.0%
poi_to_global 3.08 ±0.00 3.08 ±0.00 +0.0%
poi_resample_from_to 5.46 ±0.00 5.46 ±0.00 +0.0%
metric_voxels 3536.00 ±0.00 3536.00 ±0.00 +0.0%
metric_labels 7.00 ±0.00 7.00 ±0.00 +0.0%
metric_foreground_pct 50.17 ±0.00 50.17 ±0.00 +0.0%
nii_get_array 1.59 ±0.00 1.59 ±0.00 +0.0% (noise)
nii_compute_crop 2.90 ±0.00 2.90 ±0.00 +0.0% (noise)
nii_unique 2.84 ±0.00 2.84 ±0.00 +0.0% (noise)
poi_rescale 2.54 ±0.00 2.54 ±0.00 +0.0% (noise)
poi_local_to_global_arr 2.96 ±0.00 2.96 ±0.00 +0.0% (noise)
poi_save 1.46 ±0.00 1.46 ±0.00 +0.0% (noise)
poi_map_labels 1.71 ±0.00 1.71 ±0.00 +0.0% (noise)
poi_load 1.55 ±0.00 1.55 ±0.00 +0.0% (noise)

Gate: a measurement fails when the baseline is ≥ 1 MiB, the median grows by ≥ 50%, and Welch's t-test gives p < 0.05. metric_* rows are context only.

@Hendrik-code Hendrik-code self-assigned this Aug 31, 2026
@Hendrik-code Hendrik-code added the enhancement New feature or request label Aug 31, 2026

@robert-graf robert-graf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add TO NII

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants