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):
- crop to the bounding box of non-zero voxels;
- z-score normalise over the cropped image;
- resample to 1 mm with cubic splines (nnU-Net’s “separate z” rule for anisotropic voxels: cubic in-plane, nearest-neighbour through-plane);
- pad to at least one patch, then Gaussian-weighted sliding-window inference with 50 % overlap (optionally with 8-fold mirroring test-time augmentation);
- 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§
- HdBet
Params - 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
origininside 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), shapedims). - preprocess 🔒
- Crop to non-zero, z-score, resample to 1 mm.
Noneif the image is entirely zero. - resample_
nnunet 🔒 - nnU-Net
resample_data_or_seg_to_shapefor 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 withorderand 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)alongaxisof a C-order volume. - window_
steps 🔒 - nnU-Net
compute_steps_for_sliding_windowfor one axis.