Skip to main content

Module hdbet

Module hdbet 

Source
Expand description

HD-BET deep-learning brain extraction (onnx feature).

HD-BET v2 is an nnU-Net v2 3D U-Net (PlainConvUNet, 1 mm isotropic, 96×192×192 patches) trained on 11,751 multi-sequence clinical MRIs; it segments the brain from a single magnitude image. This module is a faithful port of nnU-Net’s inference pipeline around the exported network (hd-bet.onnx, see crate::models):

  1. crop to the bounding box of non-zero voxels;
  2. z-score normalise over the cropped image;
  3. resample to 1 mm with cubic splines (nnU-Net’s “separate z” rule for anisotropic voxels: cubic in-plane, nearest-neighbour through-plane);
  4. pad to at least one patch, then Gaussian-weighted sliding-window inference with 50 % overlap (optionally with 8-fold mirroring test-time augmentation);
  5. resample the logits back (linear; nearest through-plane for anisotropic voxels), take the argmax and un-crop.

nnU-Net works on SimpleITK arrays in (z, y, x) order, which is exactly the memory layout of the crate’s column-major (nx, ny, nz) volumes — no transposition is needed.

The input should be a magnitude image (for multi-echo GRE, the root-sum-of-squares over echoes works well) in roughly standard radiological orientation (axial slices along z), as HD-BET was trained on MNI-aligned data. HD-BET applies no post-processing; combine with crate::utils::fill_holes / erosion refinements as needed.

Reference: Isensee, F., Schell, M., Pflueger, I., et al. (2019). “Automated brain extraction of multisequence MRI using artificial neural networks.” Human Brain Mapping, 40(17):4952-4964. https://doi.org/10.1002/hbm.24750

Reference implementation: https://github.com/MIC-DKFZ/HD-BET (Apache-2.0; weights CC-BY-NC-4.0).

Structs§

HdBetParams
HD-BET inference parameters.
Preprocessed 🔒
nnU-Net-preprocessed volume plus what is needed to map predictions back.

Constants§

PATCH_DIVISOR 🔒
Required divisibility of the patch in nnU-Net (z, y, x) order (5 down-samplings, the last one in-plane only).
TARGET_SPACING 🔒
nnU-Net target spacing for HD-BET (mm).

Functions§

flip3 🔒
Mirror a C-order patch along the flagged axes (an involution).
for_each_patch_row 🔒
Visit the rows of a patch at origin inside a volume: f(volume_row_start, patch_row_start).
for_each_slice 🔒
Apply f(slice_index_along_axis, &mut value) to every voxel of a C-order volume.
gaussian_importance 🔒
nnU-Net compute_gaussian(tile, sigma_scale=1/8, value_scaling_factor=10): a Gaussian centred on the patch (σ = tile/8 per axis), peak 10.
hd_bet
Brain mask via HD-BET.
nonzero_bbox 🔒
Bounding box [start, end) of the non-zero voxels of a C-order (z, y, x) volume.
postprocess 🔒
Resample logits back to the cropped grid, argmax, un-crop. Returns the column-major mask.
predict_logits 🔒
Gaussian-weighted sliding-window logits (2 channels, C-order (z, y, x), shape dims).
preprocess 🔒
Crop to non-zero, z-score, resample to 1 mm. None if the image is entirely zero.
resample_nnunet 🔒
nnU-Net resample_data_or_seg_to_shape for one channel (non-segmentation, order_z = 0, force_separate_z = None): a plain 3D spline resize, unless the voxels are anisotropic (max/min spacing > 3), in which case each slice is resized in-plane with order and the low-resolution axis with nearest-neighbour.
separate_z_axis 🔒
nnU-Net determine_do_sep_z_and_axis(force_separate_z=None, ...): the low-resolution axis if either spacing is anisotropic by more than 3×, and that axis is unique.
slice_ranges 🔒
Per-slice (min, max) along axis of a C-order volume.
window_steps 🔒
nnU-Net compute_steps_for_sliding_window for one axis.