Skip to content

feat(nii): add relabel_by_position to renumber instances along an axis - #142

Merged
Hendrik-code merged 3 commits into
mainfrom
feat/nii-relabel-by-position
Aug 28, 2026
Merged

feat(nii): add relabel_by_position to renumber instances along an axis#142
Hendrik-code merged 3 commits into
mainfrom
feat/nii-relabel-by-position

Conversation

@Hendrik-code

Copy link
Copy Markdown
Owner

Upstreams B4 from the cross-repo survey.

What

NII.relabel_by_position(axis="I", offset=0) (plus the _-suffixed in-place variant) renumbers instance labels 1, 2, 3, … in the order their centers of mass appear when travelling along an anatomical direction. With the default axis="I", the most superior instance becomes label 1 and numbering runs downwards.

vert.relabel_by_position("I")            # topmost -> 1, next down -> 2, ...
vert.relabel_by_position("S", offset=100)  # bottom-up, starting at 101

Why

Three sibling repos each carried their own copy:

  • spineps/spineps/phase_post.pylabel_instance_top_to_bottom
  • nako-segmentation/code/utils/relabel.pylabel_top2bot and label_top2bot_advanced

All three reorient to PIR, sort components by axis 1, remap, then reorient back — and all three hardcode both the orientation and the axis.

Difference from the originals

This version resolves the direction against the image's existing orientation (get_axis for the index, axis in self.orientation for the sign, matching the idiom already used in translate_arr), so:

  • no reorientation round-trip — cheaper, and no interpolation concerns
  • the axis is a parameter rather than hardcoded to PIR/axis 1
  • the result is anatomically identical whatever orientation the caller is in, which is covered by a test that runs the same volume through ("P","I","R"), ("L","A","S") and ("A","S","L") and asserts the outputs match after reorienting back

Verification

  • 7 new tests in unit_tests/test_nii_extended.py: direction semantics, direction reversal, offset, orientation independence across three orientations, in-place equivalence, single-label case, and label/voxel-count preservation.
  • Full suite: 471 passed, 4 skipped. ruff check clean.

Note the fixture deliberately uses an image whose axis-2 letter is S, so get_axis("I") hits its opposite-direction fallback — that is the case where a naive implementation silently numbers backwards.

🤖 Generated with Claude Code

Renumbers instance labels 1, 2, 3, ... in the order their centers of mass
appear when travelling along an anatomical direction. With the default
axis="I" the most superior instance becomes label 1 and numbering runs
downwards.

Three sibling repos each carried their own version of this (spineps
label_instance_top_to_bottom, nako-segmentation label_top2bot and
label_top2bot_advanced), all of which reorient to PIR, sort by axis 1, remap
and reorient back. This version resolves the direction against the image's
existing orientation instead, so no reorientation round-trip is needed and
the result is identical whatever orientation the caller happens to be in.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

Benchmark comparison

Speed (wall time per call)

baseline b1a9537 vs head b1a9537 · 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_rescale_seg 3.13 ±0.02 2.93 ±0.05 -6.1% 0.003
poi_calc_centroids_nocrop 4.26 ±0.04 4.07 ±0.03 -4.6% 0.000
nii_rescale 39.78 ±0.26 38.93 ±0.06 -2.1% 0.005
poi_calc_poi_from_subreg_vert 12.27 ±0.06 12.51 ±0.31 +1.9% 0.127
nii_erode_msk 6.07 ±0.05 5.97 ±0.07 -1.7% 0.022
… 31 more measurements
Measurement baseline ms (median ±½·range) head ms (median ±½·range) Δ % p
nii_dilate_msk 123.60 ±0.45 125.27 ±0.32 +1.4% 0.000
nii_resample_from_to 41.60 ±0.12 41.10 ±0.25 -1.2% 0.008
nii_save 11.15 ±0.07 11.25 ±0.06 +0.9% 0.236
nii_filter_connected_components 4.08 ±0.04 4.05 ±0.01 -0.7% 0.051
nii_fill_holes 4.31 ±0.05 4.29 ±0.03 -0.5% 0.231
nii_load_img 10.46 ±0.04 10.46 ±0.06 -0.0% 0.604
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_pad_to 0.63 ±0.08 0.47 ±0.02 -25.4% (noise) 0.017
nii_set_dtype 0.44 ±0.06 0.33 ±0.01 -24.2% (noise) 0.048
poi_rescale 0.21 ±0.04 0.17 ±0.01 -20.9% (noise) 0.048
poi_save 0.37 ±0.04 0.32 ±0.01 -14.3% (noise) 0.026
nii_apply_crop 0.57 ±0.04 0.49 ±0.02 -13.6% (noise) 0.004
nii_compute_crop 0.30 ±0.02 0.26 ±0.01 -13.6% (noise) 0.004
poi_to_global 0.17 ±0.02 0.15 ±0.01 -13.0% (noise) 0.054
nii_extract_label 0.32 ±0.05 0.28 ±0.01 -12.3% (noise) 0.055
poi_reorient 0.37 ±0.02 0.33 ±0.02 -11.8% (noise) 0.001
nii_unique 0.64 ±0.04 0.58 ±0.01 -10.6% (noise) 0.017
nii_map_labels 0.99 ±0.01 0.89 ±0.03 -10.5% (noise) 0.000
poi_local_to_global_arr 0.28 ±0.01 0.25 ±0.01 -10.1% (noise) 0.003
poi_map_labels 0.15 ±0.01 0.14 ±0.01 -9.7% (noise) 0.045
nii_reorient 0.71 ±0.08 0.65 ±0.02 -8.7% (noise) 0.056
poi_resample_from_to 0.58 ±0.06 0.54 ±0.02 -7.5% (noise) 0.141
poi_calc_centroids 2.35 ±0.03 2.24 ±0.02 -4.3% (noise) 0.000
nii_get_array 0.03 ±0.00 0.03 ±0.00 -3.5% (noise) 0.212
nii_volumes 1.82 ±0.01 1.76 ±0.01 -3.3% (noise) 0.000
poi_load 0.89 ±0.03 0.86 ±0.02 -2.9% (noise) 0.193
nii_load_seg 2.55 ±0.04 2.48 ±0.03 -2.4% (noise) 0.042
nii_get_connected_components 2.06 ±0.01 2.04 ±0.03 -0.7% (noise) 0.238
nii_center_of_masses 1.66 ±0.03 1.65 ±0.01 -0.5% (noise) 0.245

ct_2d — shape (73, 47, 1)

Measurement baseline ms (median ±½·range) head ms (median ±½·range) Δ % p
nii_rescale 5.22 ±0.08 5.11 ±0.06 -2.0% 0.082
nii_resample_from_to 7.32 ±0.05 7.21 ±0.06 -1.5% 0.008
nii_dilate_msk 14.47 ±0.05 14.60 ±0.05 +0.9% 0.005
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_get_array 0.01 ±0.00 0.01 ±0.00 +11.1% (noise) 0.457
nii_unique 0.11 ±0.01 0.10 ±0.00 -8.8% (noise) 0.058
poi_map_labels 0.19 ±0.00 0.18 ±0.01 -6.9% (noise) 0.032
nii_get_connected_components 0.61 ±0.02 0.57 ±0.02 -6.7% (noise) 0.074
nii_volumes 0.27 ±0.03 0.26 ±0.01 -5.7% (noise) 0.239
nii_center_of_masses 0.19 ±0.00 0.18 ±0.01 -5.3% (noise) 0.268
nii_map_labels 0.46 ±0.01 0.44 ±0.01 -4.5% (noise) 0.031
poi_save 0.45 ±0.02 0.43 ±0.02 -3.7% (noise) 0.317
poi_rescale 0.23 ±0.01 0.22 ±0.01 -3.7% (noise) 0.430
poi_local_to_global_arr 0.32 ±0.01 0.31 ±0.01 -3.1% (noise) 0.076
poi_to_global 0.22 ±0.01 0.21 ±0.01 -3.0% (noise) 0.198
nii_rescale_seg 0.72 ±0.03 0.69 ±0.03 -3.0% (noise) 0.203
poi_calc_centroids_nocrop 1.08 ±0.02 1.06 ±0.01 -2.5% (noise) 0.008
nii_reorient 0.78 ±0.02 0.76 ±0.01 -2.4% (noise) 0.061
nii_extract_label 0.40 ±0.01 0.39 ±0.01 -2.4% (noise) 0.065
nii_load_img 1.43 ±0.05 1.39 ±0.05 -2.3% (noise) 0.555
poi_reorient 0.43 ±0.00 0.42 ±0.02 -2.0% (noise) 0.078
nii_set_dtype 0.37 ±0.02 0.36 ±0.01 -1.8% (noise) 0.246
poi_calc_centroids 0.86 ±0.03 0.85 ±0.01 -1.6% (noise) 0.251
nii_fill_holes 0.81 ±0.02 0.79 ±0.02 -1.5% (noise) 0.203
nii_apply_crop 0.62 ±0.02 0.61 ±0.02 -1.3% (noise) 0.274
nii_compute_crop 0.13 ±0.01 0.13 ±0.00 +1.3% (noise) 0.403
poi_resample_from_to 0.68 ±0.01 0.69 ±0.02 +0.9% (noise) 0.817
nii_save 1.25 ±0.02 1.25 ±0.03 -0.7% (noise) 0.765
nii_erode_msk 0.93 ±0.01 0.92 ±0.03 -0.7% (noise) 0.815
nii_filter_connected_components 0.75 ±0.04 0.75 ±0.02 +0.6% (noise) 0.382
nii_load_seg 1.55 ±0.02 1.55 ±0.02 -0.5% (noise) 0.314
nii_pad_to 0.49 ±0.01 0.49 ±0.02 -0.4% (noise) 0.758
poi_load 0.97 ±0.01 0.97 ±0.01 -0.4% (noise) 0.966

mri_3d — shape (68, 52, 67)

Measurement baseline ms (median ±½·range) head ms (median ±½·range) Δ % p
nii_save 9.28 ±0.50 9.09 ±0.06 -2.1% 0.259
nii_rescale_seg 3.08 ±0.09 3.03 ±0.09 -1.5% 0.399
poi_calc_centroids_nocrop 8.51 ±0.02 8.40 ±0.07 -1.3% 0.012
nii_rescale 37.10 ±0.25 37.44 ±0.43 +0.9% 0.202
nii_dilate_msk 159.04 ±0.77 160.45 ±0.97 +0.9% 0.021
… 31 more measurements
Measurement baseline ms (median ±½·range) head ms (median ±½·range) Δ % p
poi_calc_poi_from_subreg_vert 11.68 ±0.15 11.76 ±0.05 +0.6% 0.982
nii_erode_msk 7.63 ±0.05 7.60 ±0.09 -0.5% 0.631
nii_load_img 8.69 ±0.06 8.66 ±0.04 -0.4% 0.419
nii_resample_from_to 39.52 ±0.29 39.62 ±0.22 +0.3% 0.292
nii_fill_holes 5.26 ±0.03 5.27 ±0.02 +0.2% 0.736
nii_filter_connected_components 4.54 ±0.05 4.54 ±0.06 -0.1% 0.436
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.46 ±0.01 0.41 ±0.01 -9.4% (noise) 0.001
nii_get_array 0.05 ±0.01 0.05 ±0.00 -8.3% (noise) 0.089
nii_set_dtype 0.51 ±0.01 0.47 ±0.01 -7.9% (noise) 0.016
nii_map_labels 1.00 ±0.06 0.93 ±0.01 -7.2% (noise) 0.057
nii_unique 0.68 ±0.02 0.63 ±0.01 -6.9% (noise) 0.003
nii_pad_to 0.69 ±0.03 0.65 ±0.01 -5.7% (noise) 0.018
nii_reorient 0.86 ±0.02 0.82 ±0.01 -4.5% (noise) 0.003
poi_rescale 0.26 ±0.01 0.27 ±0.01 +4.5% (noise) 0.015
poi_save 0.51 ±0.02 0.49 ±0.01 -3.1% (noise) 0.399
poi_reorient 0.45 ±0.01 0.44 ±0.01 -3.0% (noise) 0.561
nii_compute_crop 0.32 ±0.01 0.31 ±0.01 -2.3% (noise) 0.027
poi_resample_from_to 0.72 ±0.01 0.73 ±0.03 +2.1% (noise) 0.178
nii_center_of_masses 1.98 ±0.03 1.94 ±0.01 -2.1% (noise) 0.047
nii_apply_crop 0.66 ±0.01 0.65 ±0.01 -1.8% (noise) 0.099
nii_volumes 1.94 ±0.02 1.92 ±0.07 -1.2% (noise) 0.814
nii_load_seg 2.71 ±0.04 2.69 ±0.02 -0.8% (noise) 0.245
poi_load 2.22 ±0.04 2.24 ±0.07 +0.7% (noise) 0.140
poi_local_to_global_arr 0.32 ±0.01 0.32 ±0.00 -0.7% (noise) 0.635
poi_map_labels 0.22 ±0.01 0.22 ±0.01 +0.7% (noise) 0.725
poi_calc_centroids 2.67 ±0.05 2.69 ±0.03 +0.6% (noise) 0.758
poi_to_global 0.25 ±0.01 0.25 ±0.01 -0.4% (noise) 0.983
nii_get_connected_components 2.12 ±0.04 2.13 ±0.06 +0.4% (noise) 0.896

mri_2d — shape (68, 52, 1)

Measurement baseline ms (median ±½·range) head ms (median ±½·range) Δ % p
nii_dilate_msk 19.19 ±0.12 19.48 ±0.13 +1.5% 0.008
nii_rescale 5.23 ±0.04 5.19 ±0.03 -0.7% 0.255
nii_resample_from_to 7.28 ±0.02 7.27 ±0.07 -0.1% 0.606
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%
poi_reorient 0.45 ±0.01 0.43 ±0.02 -5.6% (noise) 0.141
poi_save 0.48 ±0.01 0.50 ±0.02 +4.1% (noise) 0.076
nii_get_connected_components 0.56 ±0.02 0.58 ±0.02 +4.0% (noise) 0.359
nii_map_labels 0.44 ±0.01 0.43 ±0.02 -3.5% (noise) 0.906
nii_volumes 0.43 ±0.03 0.42 ±0.01 -2.8% (noise) 0.315
nii_pad_to 0.48 ±0.01 0.49 ±0.02 +2.7% (noise) 0.527
poi_resample_from_to 0.71 ±0.02 0.72 ±0.02 +2.5% (noise) 0.136
nii_center_of_masses 0.38 ±0.01 0.38 ±0.01 +2.5% (noise) 0.221
nii_set_dtype 0.36 ±0.03 0.35 ±0.01 -2.4% (noise) 0.475
nii_apply_crop 0.60 ±0.02 0.61 ±0.01 +2.3% (noise) 0.213
poi_calc_centroids_nocrop 1.34 ±0.02 1.36 ±0.03 +1.9% (noise) 0.088
nii_load_seg 1.54 ±0.03 1.57 ±0.05 +1.7% (noise) 0.436
nii_rescale_seg 0.69 ±0.04 0.71 ±0.03 +1.7% (noise) 0.885
poi_local_to_global_arr 0.31 ±0.01 0.31 ±0.01 -1.6% (noise) 0.698
nii_get_array 0.01 ±0.00 0.01 ±0.00 -1.3% (noise) 0.712
nii_fill_holes 1.03 ±0.00 1.04 ±0.00 +1.2% (noise) 0.003
nii_unique 0.10 ±0.01 0.11 ±0.00 +1.2% (noise) 0.594
poi_calc_centroids 1.05 ±0.01 1.06 ±0.01 +1.1% (noise) 0.385
nii_reorient 0.76 ±0.02 0.77 ±0.01 +0.9% (noise) 0.722
poi_load 1.91 ±0.04 1.90 ±0.04 -0.9% (noise) 0.709
nii_compute_crop 0.13 ±0.01 0.13 ±0.00 +0.4% (noise) 0.409
nii_extract_label 0.38 ±0.01 0.38 ±0.01 -0.4% (noise) 0.874
nii_filter_connected_components 0.80 ±0.01 0.79 ±0.02 -0.4% (noise) 0.793
poi_map_labels 0.21 ±0.01 0.22 ±0.00 +0.4% (noise) 0.709
poi_rescale 0.25 ±0.01 0.25 ±0.01 +0.3% (noise) 0.220
nii_save 1.23 ±0.01 1.24 ±0.02 +0.2% (noise) 0.196
nii_load_img 1.37 ±0.03 1.37 ±0.03 -0.1% (noise) 0.506
poi_to_global 0.24 ±0.01 0.24 ±0.01 -0.1% (noise) 0.787
nii_erode_msk 1.23 ±0.01 1.23 ±0.03 -0.1% (noise) 0.286

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 b1a9537 vs head b1a9537 · 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_pad_to 5.36 ±0.00 5.44 ±0.00 +1.5%
poi_resample_from_to 5.17 ±0.00 5.25 ±0.00 +1.5%
nii_set_dtype 5.18 ±0.00 5.25 ±0.00 +1.4%
nii_reorient 5.80 ±0.00 5.88 ±0.00 +1.4%
nii_extract_label 5.30 ±0.00 5.38 ±0.00 +1.4%
… 31 more measurements
Measurement baseline MiB (median ±½·range) head MiB (median ±½·range) Δ % p
nii_rescale_seg 5.88 ±0.00 5.96 ±0.00 +1.4%
nii_map_labels 5.43 ±0.00 5.50 ±0.00 +1.4%
nii_rescale 6.06 ±0.00 6.14 ±0.00 +1.4%
poi_calc_centroids_nocrop 5.86 ±0.00 5.93 ±0.00 +1.3%
nii_resample_from_to 6.19 ±0.00 6.27 ±0.00 +1.3%
nii_apply_crop 5.80 ±0.00 5.88 ±0.00 +1.3%
nii_load_seg 5.91 ±0.00 5.98 ±0.00 +1.3%
poi_calc_centroids 5.99 ±0.00 6.06 ±0.00 +1.2%
nii_get_connected_components 6.55 ±0.00 6.63 ±0.00 +1.1%
nii_fill_holes 6.22 ±0.00 6.29 ±0.00 +1.1%
nii_filter_connected_components 6.80 ±0.00 6.88 ±0.00 +1.1%
poi_calc_poi_from_subreg_vert 7.05 ±0.00 7.12 ±0.00 +1.1%
nii_dilate_msk 5.86 ±0.00 5.92 ±0.00 +1.0%
nii_erode_msk 5.88 ±0.00 5.93 ±0.00 +1.0%
nii_center_of_masses 3.27 ±0.00 3.28 ±0.00 +0.1%
nii_volumes 3.52 ±0.00 3.53 ±0.00 +0.1%
nii_load_img 3.53 ±0.00 3.53 ±0.00 +0.1%
nii_save 3.71 ±0.00 3.71 ±0.00 +0.1%
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%
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.2% (noise)
nii_compute_crop 2.90 ±0.00 2.90 ±0.00 +0.1% (noise)
nii_unique 2.96 ±0.00 2.96 ±0.00 +0.1% (noise)
poi_rescale 2.61 ±0.00 2.61 ±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.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
poi_resample_from_to 5.10 ±0.00 5.18 ±0.00 +1.6%
nii_pad_to 5.29 ±0.00 5.37 ±0.00 +1.6%
nii_set_dtype 5.11 ±0.00 5.19 ±0.00 +1.5%
nii_reorient 5.73 ±0.00 5.81 ±0.00 +1.4%
nii_extract_label 5.24 ±0.00 5.31 ±0.00 +1.4%
… 30 more measurements
Measurement baseline MiB (median ±½·range) head MiB (median ±½·range) Δ % p
nii_rescale_seg 5.81 ±0.00 5.89 ±0.00 +1.4%
poi_calc_centroids_nocrop 5.85 ±0.00 5.93 ±0.00 +1.4%
nii_map_labels 5.36 ±0.00 5.44 ±0.00 +1.4%
nii_rescale 6.00 ±0.00 6.08 ±0.00 +1.4%
nii_apply_crop 5.74 ±0.00 5.81 ±0.00 +1.3%
nii_resample_from_to 6.12 ±0.00 6.20 ±0.00 +1.3%
nii_load_seg 5.84 ±0.00 5.92 ±0.00 +1.3%
poi_calc_centroids 5.93 ±0.00 6.00 ±0.00 +1.3%
nii_get_connected_components 6.49 ±0.00 6.56 ±0.00 +1.1%
nii_fill_holes 6.16 ±0.00 6.23 ±0.00 +1.1%
nii_filter_connected_components 6.74 ±0.00 6.81 ±0.00 +1.1%
nii_dilate_msk 5.79 ±0.00 5.85 ±0.00 +1.0%
nii_erode_msk 5.81 ±0.00 5.87 ±0.00 +1.0%
poi_to_global 3.02 ±0.00 3.02 ±0.00 +0.1%
nii_center_of_masses 3.21 ±0.00 3.21 ±0.00 +0.1%
nii_volumes 3.46 ±0.00 3.46 ±0.00 +0.1%
nii_load_img 3.46 ±0.00 3.46 ±0.00 +0.1%
nii_save 3.64 ±0.00 3.65 ±0.00 +0.1%
poi_reorient 3.77 ±0.00 3.77 ±0.00 +0.1%
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%
poi_save 1.34 ±0.00 1.34 ±0.00 +0.3% (noise)
poi_load 1.55 ±0.00 1.55 ±0.00 +0.3% (noise)
nii_get_array 1.58 ±0.00 1.59 ±0.00 +0.2% (noise)
poi_map_labels 1.71 ±0.00 1.71 ±0.00 +0.2% (noise)
poi_rescale 2.54 ±0.00 2.54 ±0.00 +0.2% (noise)
nii_compute_crop 2.83 ±0.00 2.84 ±0.00 +0.1% (noise)
poi_local_to_global_arr 2.89 ±0.00 2.89 ±0.00 +0.1% (noise)
nii_unique 2.89 ±0.00 2.90 ±0.00 +0.1% (noise)

mri_3d — shape (68, 52, 67)

Measurement baseline MiB (median ±½·range) head MiB (median ±½·range) Δ % p
poi_resample_from_to 5.10 ±0.00 5.18 ±0.00 +1.6%
nii_pad_to 5.29 ±0.00 5.37 ±0.00 +1.6%
nii_set_dtype 5.18 ±0.00 5.25 ±0.00 +1.4%
nii_reorient 5.73 ±0.00 5.81 ±0.00 +1.4%
poi_calc_centroids_nocrop 5.79 ±0.00 5.87 ±0.00 +1.4%
… 31 more measurements
Measurement baseline MiB (median ±½·range) head MiB (median ±½·range) Δ % p
nii_extract_label 5.24 ±0.00 5.31 ±0.00 +1.4%
nii_rescale_seg 5.81 ±0.00 5.89 ±0.00 +1.4%
nii_map_labels 5.36 ±0.00 5.44 ±0.00 +1.4%
nii_rescale 6.00 ±0.00 6.08 ±0.00 +1.4%
nii_resample_from_to 6.12 ±0.00 6.20 ±0.00 +1.3%
nii_apply_crop 5.74 ±0.00 5.81 ±0.00 +1.3%
nii_load_seg 5.84 ±0.00 5.92 ±0.00 +1.3%
poi_calc_centroids 5.93 ±0.00 6.00 ±0.00 +1.3%
nii_get_connected_components 6.49 ±0.00 6.56 ±0.00 +1.1%
nii_fill_holes 6.16 ±0.00 6.23 ±0.00 +1.1%
nii_filter_connected_components 6.74 ±0.00 6.81 ±0.00 +1.1%
poi_calc_poi_from_subreg_vert 7.05 ±0.00 7.12 ±0.00 +1.1%
nii_dilate_msk 5.79 ±0.00 5.85 ±0.00 +1.0%
nii_erode_msk 5.81 ±0.00 5.87 ±0.00 +1.0%
poi_to_global 3.02 ±0.00 3.02 ±0.00 +0.1%
nii_center_of_masses 3.21 ±0.00 3.21 ±0.00 +0.1%
nii_volumes 3.46 ±0.00 3.46 ±0.00 +0.1%
nii_load_img 3.52 ±0.03 3.53 ±0.00 +0.1% 0.260
nii_save 3.64 ±0.00 3.65 ±0.00 +0.1%
poi_reorient 3.77 ±0.00 3.77 ±0.00 +0.1%
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%
poi_save 1.40 ±0.00 1.40 ±0.00 +0.3% (noise)
poi_load 1.55 ±0.00 1.55 ±0.00 +0.3% (noise)
nii_get_array 1.58 ±0.00 1.59 ±0.00 +0.2% (noise)
poi_map_labels 1.71 ±0.00 1.71 ±0.00 +0.2% (noise)
poi_rescale 2.54 ±0.00 2.54 ±0.00 +0.2% (noise)
nii_compute_crop 2.83 ±0.00 2.84 ±0.00 +0.1% (noise)
poi_local_to_global_arr 2.89 ±0.00 2.89 ±0.00 +0.1% (noise)
nii_unique 2.89 ±0.00 2.90 ±0.00 +0.1% (noise)

mri_2d — shape (68, 52, 1)

Measurement baseline MiB (median ±½·range) head MiB (median ±½·range) Δ % p
poi_resample_from_to 5.10 ±0.00 5.18 ±0.00 +1.6%
nii_pad_to 5.29 ±0.00 5.37 ±0.00 +1.6%
nii_set_dtype 5.18 ±0.00 5.25 ±0.00 +1.4%
nii_reorient 5.73 ±0.00 5.81 ±0.00 +1.4%
nii_extract_label 5.24 ±0.00 5.31 ±0.00 +1.4%
… 30 more measurements
Measurement baseline MiB (median ±½·range) head MiB (median ±½·range) Δ % p
nii_rescale_seg 5.81 ±0.00 5.89 ±0.00 +1.4%
poi_calc_centroids_nocrop 5.85 ±0.00 5.93 ±0.00 +1.4%
nii_map_labels 5.36 ±0.00 5.44 ±0.00 +1.4%
nii_rescale 6.00 ±0.00 6.08 ±0.00 +1.4%
nii_resample_from_to 6.12 ±0.00 6.20 ±0.00 +1.3%
nii_apply_crop 5.74 ±0.00 5.81 ±0.00 +1.3%
nii_load_seg 5.84 ±0.00 5.92 ±0.00 +1.3%
poi_calc_centroids 5.93 ±0.00 6.00 ±0.00 +1.3%
nii_get_connected_components 6.49 ±0.00 6.56 ±0.00 +1.1%
nii_fill_holes 6.16 ±0.00 6.23 ±0.00 +1.1%
nii_filter_connected_components 6.74 ±0.00 6.81 ±0.00 +1.1%
nii_dilate_msk 5.79 ±0.00 5.85 ±0.00 +1.0%
nii_erode_msk 5.81 ±0.00 5.87 ±0.00 +1.0%
poi_to_global 3.02 ±0.00 3.02 ±0.00 +0.1%
nii_center_of_masses 3.21 ±0.00 3.21 ±0.00 +0.1%
nii_volumes 3.46 ±0.00 3.46 ±0.00 +0.1%
nii_load_img 3.52 ±0.00 3.53 ±0.00 +0.1%
nii_save 3.64 ±0.00 3.65 ±0.00 +0.1%
poi_reorient 3.77 ±0.00 3.77 ±0.00 +0.1%
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%
poi_save 1.40 ±0.00 1.40 ±0.00 +0.3% (noise)
poi_load 1.55 ±0.00 1.55 ±0.00 +0.3% (noise)
nii_get_array 1.58 ±0.00 1.59 ±0.00 +0.2% (noise)
poi_map_labels 1.71 ±0.00 1.71 ±0.00 +0.2% (noise)
poi_rescale 2.54 ±0.00 2.54 ±0.00 +0.2% (noise)
nii_compute_crop 2.83 ±0.00 2.84 ±0.00 +0.1% (noise)
poi_local_to_global_arr 2.89 ±0.00 2.89 ±0.00 +0.1% (noise)
nii_unique 2.89 ±0.00 2.90 ±0.00 +0.1% (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 28, 2026
@Hendrik-code Hendrik-code added the enhancement New feature or request label Aug 28, 2026
@Hendrik-code
Hendrik-code merged commit a70d8d3 into main Aug 28, 2026
6 checks passed
@Hendrik-code
Hendrik-code deleted the feat/nii-relabel-by-position branch August 28, 2026 10:42
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