%global srcname HD-BET %global import_name HD_BET Name: python-hd-bet Version: 2.0.1 Release: 1%{?dist} Summary: Brain extraction for multi-sequence MRI with nnU-Net License: Apache-2.0 URL: https://github.com/MIC-DKFZ/HD-BET # The GitHub tag rather than the PyPI sdist: it carries the readme, which the # sdist leaves out although pyproject.toml names it. Source0: %{url}/archive/v%{version}/%{srcname}-%{version}.tar.gz BuildArch: noarch BuildRequires: python3-devel BuildRequires: pyproject-rpm-macros # %%check runs apply_bet on a synthetic volume and the CLI's --help BuildRequires: python3dist(simpleitk) %global _description %{expand: HD-BET removes the skull and other non-brain tissue from MRI of the head. It was trained on T1, contrast-enhanced T1, T2 and FLAIR scans of brain-tumour patients from many scanners and centres, and handles pathology and post- operative anatomy that classical brain extraction tools often fail on. Since version 2.0 it is a thin wrapper around nnU-Net v2 inference. The trained network (114 MB, CC BY-NC 4.0, Zenodo record 14445620) is not part of this package: the hd-bet command downloads it on first use into ~/hd-bet_params. Pass "-device cpu" on machines without a CUDA GPU.} %description %_description %package -n python3-hd-bet Summary: %{summary} %description -n python3-hd-bet %_description %prep %autosetup -n %{srcname}-%{version} # pyproject.toml names README.md; the file in the tag is readme.md. sed -i 's/^readme = "README.md"/readme = "readme.md"/' pyproject.toml grep -q '^readme = "readme.md"' pyproject.toml %generate_buildrequires %pyproject_buildrequires %build %pyproject_wheel %install %pyproject_install %pyproject_save_files %{import_name} %check %pyproject_check_import # The CLI parses its arguments before it touches the network. %{buildroot}%{_bindir}/hd-bet --help | grep -q -- '--disable_tta' # apply_bet is the post-processing step that turns the network's mask into the # brain-extracted image. Check it keeps voxels, zeroes the rest and carries the # geometry over, on a synthetic volume (the network itself needs the weights). cd %{_builddir} %{py3_test_envvars} %{python3} - <<'EOF' import numpy as np, SimpleITK as sitk from HD_BET.hd_bet_prediction import apply_bet img = np.arange(10*12*14, dtype=np.float32).reshape(10, 12, 14) + 1 mask = np.zeros_like(img, dtype=np.uint8); mask[2:8, 3:9, 4:10] = 1 i = sitk.GetImageFromArray(img); i.SetSpacing((0.9, 1.1, 1.3)); i.SetOrigin((-5, 7, 3)) m = sitk.GetImageFromArray(mask); m.CopyInformation(i) sitk.WriteImage(i, "t1.nii.gz"); sitk.WriteImage(m, "t1_bet.nii.gz") apply_bet("t1.nii.gz", "t1_bet.nii.gz", "out.nii.gz") o = sitk.ReadImage("out.nii.gz"); a = sitk.GetArrayFromImage(o) assert np.array_equal(a[mask == 1], img[mask == 1]) assert not a[mask == 0].any() assert np.allclose(o.GetSpacing(), (0.9, 1.1, 1.3)) and np.allclose(o.GetOrigin(), (-5, 7, 3)) print("apply_bet ok:", int(mask.sum()), "voxels kept") EOF %files -n python3-hd-bet -f %{pyproject_files} %license LICENSE %doc readme.md %{_bindir}/hd-bet %changelog * Fri Oct 16 2026 Morgan Hough - 2.0.1-1 - Initial package. The CC BY-NC 4.0 weights stay a first-use download.