brainles-preprocessing 0.4.0__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/PKG-INFO +10 -6
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/README.md +7 -3
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/brain_extraction/brain_extractor.py +6 -6
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/constants.py +3 -2
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/defacing/defacer.py +6 -6
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/defacing/quickshear/quickshear.py +7 -4
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/modality.py +17 -9
- brainles_preprocessing-0.5.0/brainles_preprocessing/n4_bias_correction/__init__.py +2 -0
- brainles_preprocessing-0.5.0/brainles_preprocessing/n4_bias_correction/n4_bias_corrector.py +13 -0
- brainles_preprocessing-0.5.0/brainles_preprocessing/n4_bias_correction/sitk/sitk_n4_bias_corrector.py +82 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/preprocessor.py +89 -16
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/ANTs/ANTs.py +4 -4
- brainles_preprocessing-0.5.0/brainles_preprocessing/registration/niftyreg/__init__.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg.py +2 -2
- brainles_preprocessing-0.4.0/brainles_preprocessing/back_to_native.py → brainles_preprocessing-0.5.0/brainles_preprocessing/transform.py +32 -17
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/pyproject.toml +3 -3
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/LICENSE +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/__init__.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/brain_extraction/__init__.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/brats/__init__.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/brats/t1_centric.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/brats/t1c_centric.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/cli.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/defacing/__init__.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/defacing/quickshear/__init__.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/defacing/quickshear/nipy_quickshear.py +0 -0
- {brainles_preprocessing-0.4.0/brainles_preprocessing/registration/ANTs → brainles_preprocessing-0.5.0/brainles_preprocessing/n4_bias_correction/sitk}/__init__.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/normalization/__init__.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/normalization/normalizer_base.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/normalization/percentile_normalizer.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/normalization/windowing_normalizer.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/ANTs/TODO_ANTs_parameters.py +0 -0
- {brainles_preprocessing-0.4.0/brainles_preprocessing/registration/elastix → brainles_preprocessing-0.5.0/brainles_preprocessing/registration/ANTs}/__init__.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/__init__.py +0 -0
- {brainles_preprocessing-0.4.0/brainles_preprocessing/registration/greedy → brainles_preprocessing-0.5.0/brainles_preprocessing/registration/elastix}/__init__.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/elastix/elastix.py +0 -0
- {brainles_preprocessing-0.4.0/brainles_preprocessing/registration/niftyreg → brainles_preprocessing-0.5.0/brainles_preprocessing/registration/greedy}/__init__.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/greedy/greedy.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/bin/groupwise_niftyreg_params.sh +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/bin/groupwise_niftyreg_run.sh +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/bin/reg_aladin +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/bin/reg_average +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/bin/reg_f3d +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/bin/reg_jacobian +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/bin/reg_measure +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/bin/reg_resample +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/bin/reg_tools +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/bin/reg_transform +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/AffineDeformationFieldKernel.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/AladinContent.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/BlockMatchingKernel.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/CPUAffineDeformationFieldKernel.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/CPUBlockMatchingKernel.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/CPUConvolutionKernel.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/CPUKernelFactory.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/CPUOptimiseKernel.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/CPUResampleImageKernel.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/ConvolutionKernel.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/Kernel.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/KernelFactory.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/OptimiseKernel.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/Platform.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/ResampleImageKernel.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_ReadWriteImage.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_ReadWriteMatrix.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_aladin.cpp +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_aladin.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_aladin_sym.cpp +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_aladin_sym.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_base.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_blockMatching.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_dti.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_f3d.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_f3d2.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_f3d_sym.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_femTrans.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_globalTrans.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_kld.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_lncc.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_localTrans.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_localTrans_jac.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_localTrans_regul.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_macros.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_maths.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_maths_eigen.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_measure.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_mind.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_nmi.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_optimiser.cpp +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_optimiser.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_resampling.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_splineBasis.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_ssd.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_stringFormat.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/_reg_tools.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/nifti1.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/nifti1_io.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/png.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/pngconf.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/pngdebug.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/pnginfo.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/pnglibconf.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/pngpriv.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/pngstruct.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/readpng.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/reg_png.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/zlib.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/znzlib.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/niftyreg_1.5.68/include/zutil.h +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/reg_aladin +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/reg_resample +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/rigid_reg.sh +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/niftyreg/niftyreg_scripts/transform.sh +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/registration/registrator.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/utils/__init__.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/utils/generic.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/utils/logging_utils.py +0 -0
- {brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/utils/zenodo.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: brainles_preprocessing
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Tool for preprocessing tasks in biomedical imaging, with a focus on (but not limited to) multi-modal brain MRI
|
|
5
5
|
License: Apache-2.0
|
|
6
6
|
Keywords: brain tumor,glioma,BraTS,skullstripping,brain extraction
|
|
@@ -20,17 +20,17 @@ Provides-Extra: all
|
|
|
20
20
|
Provides-Extra: itk-elastix
|
|
21
21
|
Provides-Extra: picsl-greedy
|
|
22
22
|
Requires-Dist: antspyx (>=0.5.4,<1.0.0)
|
|
23
|
-
Requires-Dist: auxiliary (>=0.
|
|
23
|
+
Requires-Dist: auxiliary (>=0.3.1)
|
|
24
24
|
Requires-Dist: black (>=22.1.0,<23.0.0)
|
|
25
25
|
Requires-Dist: brainles_hd_bet (>=0.0.10,<1.0.0)
|
|
26
26
|
Requires-Dist: itk-elastix (>=0.20.0,<0.21.0) ; extra == "all" or extra == "itk-elastix"
|
|
27
27
|
Requires-Dist: nibabel (>=3.2.1)
|
|
28
28
|
Requires-Dist: numpy (>=1.23.0,<2.0.0)
|
|
29
|
-
Requires-Dist: path (>=16.10.0,<17.0.0)
|
|
30
29
|
Requires-Dist: pathlib (>=1.0.1,<2.0.0)
|
|
31
30
|
Requires-Dist: picsl_greedy (>=0.0.6,<0.0.7) ; extra == "all" or extra == "picsl-greedy"
|
|
32
31
|
Requires-Dist: rich (>=13.6.0,<14.0.0)
|
|
33
32
|
Requires-Dist: scipy (<1.14)
|
|
33
|
+
Requires-Dist: simpleitk (>=2.2.1)
|
|
34
34
|
Requires-Dist: tqdm (>=4.64.1,<5.0.0)
|
|
35
35
|
Requires-Dist: ttictoc (>=0.5.6,<0.6.0)
|
|
36
36
|
Requires-Dist: typer (>=0.15.0,<0.16.0)
|
|
@@ -49,9 +49,10 @@ Description-Content-Type: text/markdown
|
|
|
49
49
|
|
|
50
50
|
`BrainLes preprocessing` is a comprehensive tool for preprocessing tasks in biomedical imaging, with a focus on (but not limited to) multi-modal brain MRI. It can be used to build modular preprocessing pipelines:
|
|
51
51
|
|
|
52
|
-
This includes **normalization**, **co-registration**, **atlas registration
|
|
52
|
+
This includes **normalization**, **co-registration**, **atlas registration**, **skullstripping / brain extraction**, **N4 Bias correction** and **defacing**.
|
|
53
|
+
We provide means to transform images and segmentations in both directions between native and atlas space.
|
|
53
54
|
|
|
54
|
-
BrainLes is written `backend-agnostic` meaning it allows to swap
|
|
55
|
+
BrainLes is written modular and `backend-agnostic` meaning it allows to skip or swap registration, brain extraction, N4 bias correction and defacing tools.
|
|
55
56
|
|
|
56
57
|
<!-- TODO include image here -->
|
|
57
58
|
|
|
@@ -125,7 +126,7 @@ moving_modalities = [
|
|
|
125
126
|
)
|
|
126
127
|
]
|
|
127
128
|
|
|
128
|
-
# instantiate and run the preprocessor using defaults for registration
|
|
129
|
+
# instantiate and run the preprocessor using defaults for backends (registration, brain extraction, bias correction, defacing)
|
|
129
130
|
preprocessor = Preprocessor(
|
|
130
131
|
center_modality=center,
|
|
131
132
|
moving_modalities=moving_modalities,
|
|
@@ -166,6 +167,9 @@ We currently provide support for [ANTs](https://github.com/ANTsX/ANTs) (default)
|
|
|
166
167
|
We provide the SRI-24 atlas from this [publication](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2915788/).
|
|
167
168
|
However, custom atlases in NIfTI format are supported.
|
|
168
169
|
|
|
170
|
+
### N4 Bias correction
|
|
171
|
+
We currently provide support for N4 Bias correction based on [SimpleITK](https://simpleitk.org/)
|
|
172
|
+
|
|
169
173
|
### Brain extraction
|
|
170
174
|
We currently provide support for [HD-BET](https://github.com/MIC-DKFZ/HD-BET).
|
|
171
175
|
|
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
`BrainLes preprocessing` is a comprehensive tool for preprocessing tasks in biomedical imaging, with a focus on (but not limited to) multi-modal brain MRI. It can be used to build modular preprocessing pipelines:
|
|
12
12
|
|
|
13
|
-
This includes **normalization**, **co-registration**, **atlas registration
|
|
13
|
+
This includes **normalization**, **co-registration**, **atlas registration**, **skullstripping / brain extraction**, **N4 Bias correction** and **defacing**.
|
|
14
|
+
We provide means to transform images and segmentations in both directions between native and atlas space.
|
|
14
15
|
|
|
15
|
-
BrainLes is written `backend-agnostic` meaning it allows to swap
|
|
16
|
+
BrainLes is written modular and `backend-agnostic` meaning it allows to skip or swap registration, brain extraction, N4 bias correction and defacing tools.
|
|
16
17
|
|
|
17
18
|
<!-- TODO include image here -->
|
|
18
19
|
|
|
@@ -86,7 +87,7 @@ moving_modalities = [
|
|
|
86
87
|
)
|
|
87
88
|
]
|
|
88
89
|
|
|
89
|
-
# instantiate and run the preprocessor using defaults for registration
|
|
90
|
+
# instantiate and run the preprocessor using defaults for backends (registration, brain extraction, bias correction, defacing)
|
|
90
91
|
preprocessor = Preprocessor(
|
|
91
92
|
center_modality=center,
|
|
92
93
|
moving_modalities=moving_modalities,
|
|
@@ -127,6 +128,9 @@ We currently provide support for [ANTs](https://github.com/ANTsX/ANTs) (default)
|
|
|
127
128
|
We provide the SRI-24 atlas from this [publication](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2915788/).
|
|
128
129
|
However, custom atlases in NIfTI format are supported.
|
|
129
130
|
|
|
131
|
+
### N4 Bias correction
|
|
132
|
+
We currently provide support for N4 Bias correction based on [SimpleITK](https://simpleitk.org/)
|
|
133
|
+
|
|
130
134
|
### Brain extraction
|
|
131
135
|
We currently provide support for [HD-BET](https://github.com/MIC-DKFZ/HD-BET).
|
|
132
136
|
|
|
@@ -5,7 +5,7 @@ from pathlib import Path
|
|
|
5
5
|
from typing import Optional, Union
|
|
6
6
|
from enum import Enum
|
|
7
7
|
|
|
8
|
-
from auxiliary.
|
|
8
|
+
from auxiliary.io import read_image, write_image
|
|
9
9
|
from brainles_hd_bet import run_hd_bet
|
|
10
10
|
|
|
11
11
|
|
|
@@ -55,8 +55,8 @@ class BrainExtractor:
|
|
|
55
55
|
|
|
56
56
|
try:
|
|
57
57
|
# Read data
|
|
58
|
-
input_data =
|
|
59
|
-
mask_data =
|
|
58
|
+
input_data = read_image(str(input_image_path))
|
|
59
|
+
mask_data = read_image(str(mask_path))
|
|
60
60
|
except FileNotFoundError as e:
|
|
61
61
|
raise FileNotFoundError(f"File not found: {e.filename}") from e
|
|
62
62
|
except Exception as e:
|
|
@@ -70,10 +70,10 @@ class BrainExtractor:
|
|
|
70
70
|
masked_data = input_data * mask_data
|
|
71
71
|
|
|
72
72
|
try:
|
|
73
|
-
|
|
73
|
+
write_image(
|
|
74
74
|
input_array=masked_data,
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
output_path=str(bet_image_path),
|
|
76
|
+
reference_path=str(input_image_path),
|
|
77
77
|
create_parent_directory=True,
|
|
78
78
|
)
|
|
79
79
|
except Exception as e:
|
|
@@ -2,7 +2,7 @@ from abc import ABC, abstractmethod
|
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
from typing import Union
|
|
4
4
|
|
|
5
|
-
from auxiliary.
|
|
5
|
+
from auxiliary.io import read_image, write_image
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class Defacer(ABC):
|
|
@@ -52,8 +52,8 @@ class Defacer(ABC):
|
|
|
52
52
|
|
|
53
53
|
try:
|
|
54
54
|
# Read data
|
|
55
|
-
input_data =
|
|
56
|
-
mask_data =
|
|
55
|
+
input_data = read_image(str(input_image_path))
|
|
56
|
+
mask_data = read_image(str(mask_path))
|
|
57
57
|
except Exception as e:
|
|
58
58
|
raise RuntimeError(
|
|
59
59
|
f"An error occurred while reading input files: {e}"
|
|
@@ -67,9 +67,9 @@ class Defacer(ABC):
|
|
|
67
67
|
masked_data = input_data * mask_data
|
|
68
68
|
|
|
69
69
|
# Save the defaced image
|
|
70
|
-
|
|
70
|
+
write_image(
|
|
71
71
|
input_array=masked_data,
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
output_path=str(defaced_image_path),
|
|
73
|
+
reference_path=str(input_image_path),
|
|
74
74
|
create_parent_directory=True,
|
|
75
75
|
)
|
|
@@ -2,10 +2,10 @@ from pathlib import Path
|
|
|
2
2
|
from typing import Union
|
|
3
3
|
|
|
4
4
|
import nibabel as nib
|
|
5
|
+
from auxiliary.io import read_image, write_image
|
|
5
6
|
|
|
6
7
|
from brainles_preprocessing.defacing.defacer import Defacer
|
|
7
8
|
from brainles_preprocessing.defacing.quickshear.nipy_quickshear import run_quickshear
|
|
8
|
-
from auxiliary.nifti.io import write_nifti
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class QuickshearDefacer(Defacer):
|
|
@@ -56,8 +56,11 @@ class QuickshearDefacer(Defacer):
|
|
|
56
56
|
|
|
57
57
|
bet_img = nib.load(str(input_image_path))
|
|
58
58
|
mask = run_quickshear(bet_img=bet_img, buffer=self.buffer)
|
|
59
|
-
|
|
59
|
+
|
|
60
|
+
# transpose to match simpletik order
|
|
61
|
+
mask = mask.transpose(2, 1, 0)
|
|
62
|
+
write_image(
|
|
60
63
|
input_array=mask,
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
output_path=str(mask_image_path),
|
|
65
|
+
reference_path=str(input_image_path),
|
|
63
66
|
)
|
{brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/modality.py
RENAMED
|
@@ -4,7 +4,7 @@ import warnings
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
from typing import Dict, Optional, Union
|
|
6
6
|
|
|
7
|
-
from auxiliary.
|
|
7
|
+
from auxiliary.io import read_image, write_image
|
|
8
8
|
|
|
9
9
|
from brainles_preprocessing.brain_extraction.brain_extractor import BrainExtractor
|
|
10
10
|
from brainles_preprocessing.constants import PreprocessorSteps
|
|
@@ -34,6 +34,7 @@ class Modality:
|
|
|
34
34
|
normalized_skull_output_path (str or Path, optional): Path to save the normalized modality data with skull. Requires a normalizer.
|
|
35
35
|
normalized_defaced_output_path (str or Path, optional): Path to save the normalized defaced modality data. Requires a normalizer.
|
|
36
36
|
atlas_correction (bool, optional): Indicates whether atlas correction should be performed.
|
|
37
|
+
n4_bias_correction (bool, optional): Indicates whether N4 bias correction should be performed.
|
|
37
38
|
|
|
38
39
|
Attributes:
|
|
39
40
|
modality_name (str): Name of the modality.
|
|
@@ -47,6 +48,7 @@ class Modality:
|
|
|
47
48
|
normalized_defaced_output_path (str or Path, optional): Path to save the normalized defaced modality data. Requires a normalizer.
|
|
48
49
|
bet (bool): Indicates whether brain extraction is enabled.
|
|
49
50
|
atlas_correction (bool): Indicates whether atlas correction should be performed.
|
|
51
|
+
n4_bias_correction (bool): Indicates whether N4 bias correction should be performed.
|
|
50
52
|
coregistration_transform_path (str or None): Path to the coregistration transformation matrix, will be set after coregistration.
|
|
51
53
|
|
|
52
54
|
Example:
|
|
@@ -72,6 +74,7 @@ class Modality:
|
|
|
72
74
|
normalized_skull_output_path: Optional[Union[str, Path]] = None,
|
|
73
75
|
normalized_defaced_output_path: Optional[Union[str, Path]] = None,
|
|
74
76
|
atlas_correction: bool = True,
|
|
77
|
+
n4_bias_correction: bool = False,
|
|
75
78
|
) -> None:
|
|
76
79
|
# Basics
|
|
77
80
|
self.modality_name = modality_name
|
|
@@ -79,6 +82,7 @@ class Modality:
|
|
|
79
82
|
self.current = self.input_path
|
|
80
83
|
self.normalizer = normalizer
|
|
81
84
|
self.atlas_correction = atlas_correction
|
|
85
|
+
self.n4_bias_correction = n4_bias_correction
|
|
82
86
|
self.transformation_paths: Dict[PreprocessorSteps, Path | None] = {}
|
|
83
87
|
|
|
84
88
|
# Check that atleast one output is generated
|
|
@@ -195,12 +199,12 @@ class Modality:
|
|
|
195
199
|
|
|
196
200
|
# Normalize the image
|
|
197
201
|
if self.normalizer:
|
|
198
|
-
image =
|
|
202
|
+
image = read_image(str(self.current))
|
|
199
203
|
normalized_image = self.normalizer.normalize(image=image)
|
|
200
|
-
|
|
204
|
+
write_image(
|
|
201
205
|
input_array=normalized_image,
|
|
202
|
-
|
|
203
|
-
|
|
206
|
+
output_path=str(self.current),
|
|
207
|
+
reference_path=str(self.current),
|
|
204
208
|
)
|
|
205
209
|
else:
|
|
206
210
|
logger.info("No normalizer specified; skipping normalization.")
|
|
@@ -505,12 +509,12 @@ class Modality:
|
|
|
505
509
|
if normalization:
|
|
506
510
|
if self.normalizer is None:
|
|
507
511
|
raise ValueError("Normalizer is required for normalization.")
|
|
508
|
-
image =
|
|
512
|
+
image = read_image(str(self.current))
|
|
509
513
|
normalized_image = self.normalizer.normalize(image=image)
|
|
510
|
-
|
|
514
|
+
write_image(
|
|
511
515
|
input_array=normalized_image,
|
|
512
|
-
|
|
513
|
-
|
|
516
|
+
output_path=str(output_path),
|
|
517
|
+
reference_path=str(self.current),
|
|
514
518
|
)
|
|
515
519
|
else:
|
|
516
520
|
shutil.copyfile(
|
|
@@ -534,6 +538,7 @@ class CenterModality(Modality):
|
|
|
534
538
|
normalized_skull_output_path (str or Path, optional): Path to save the normalized modality data with skull. Requires a normalizer.
|
|
535
539
|
normalized_defaced_output_path (str or Path, optional): Path to save the normalized defaced modality data. Requires a normalizer.
|
|
536
540
|
atlas_correction (bool, optional): Indicates whether atlas correction should be performed.
|
|
541
|
+
n4_bias_correction (bool, optional): Indicates whether N4 bias correction should be performed.
|
|
537
542
|
bet_mask_output_path (str or Path, optional): Path to save the brain extraction mask.
|
|
538
543
|
defacing_mask_output_path (str or Path, optional): Path to save the defacing mask.
|
|
539
544
|
|
|
@@ -549,6 +554,7 @@ class CenterModality(Modality):
|
|
|
549
554
|
normalized_defaced_output_path (str or Path, optional): Path to save the normalized defaced modality data. Requires a normalizer.
|
|
550
555
|
bet (bool): Indicates whether brain extraction is enabled.
|
|
551
556
|
atlas_correction (bool): Indicates whether atlas correction should be performed.
|
|
557
|
+
n4_bias_correction (bool): Indicates whether N4 bias correction should be performed.
|
|
552
558
|
bet_mask_output_path (Path, optional): Path to save the brain extraction mask.
|
|
553
559
|
defacing_mask_output_path (Path, optional): Path to save the defacing mask.
|
|
554
560
|
|
|
@@ -575,6 +581,7 @@ class CenterModality(Modality):
|
|
|
575
581
|
normalized_skull_output_path: Optional[Union[str, Path]] = None,
|
|
576
582
|
normalized_defaced_output_path: Optional[Union[str, Path]] = None,
|
|
577
583
|
atlas_correction: bool = True,
|
|
584
|
+
n4_bias_correction: bool = False,
|
|
578
585
|
bet_mask_output_path: Optional[Union[str, Path]] = None,
|
|
579
586
|
defacing_mask_output_path: Optional[Union[str, Path]] = None,
|
|
580
587
|
) -> None:
|
|
@@ -589,6 +596,7 @@ class CenterModality(Modality):
|
|
|
589
596
|
normalized_skull_output_path=normalized_skull_output_path,
|
|
590
597
|
normalized_defaced_output_path=normalized_defaced_output_path,
|
|
591
598
|
atlas_correction=atlas_correction,
|
|
599
|
+
n4_bias_correction=n4_bias_correction,
|
|
592
600
|
)
|
|
593
601
|
# Only for CenterModality
|
|
594
602
|
self.bet_mask_output_path = (
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Callable, Optional, Union
|
|
3
|
+
|
|
4
|
+
import SimpleITK as sitk
|
|
5
|
+
from auxiliary.io import write_image
|
|
6
|
+
|
|
7
|
+
from brainles_preprocessing.n4_bias_correction.n4_bias_corrector import N4BiasCorrector
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SitkN4BiasCorrector(N4BiasCorrector):
|
|
11
|
+
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
mask_func: Optional[Callable[[sitk.Image], sitk.Image]] = None,
|
|
15
|
+
n_max_iterations: Optional[int] = None,
|
|
16
|
+
n_fitting_levels: int = 3,
|
|
17
|
+
) -> None:
|
|
18
|
+
"""
|
|
19
|
+
N4 Bias Corrector using SimpleITK.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
mask_func (Optional[Callable[[sitk.Image], sitk.Image]], optional):
|
|
23
|
+
Function that generates a mask from an image.
|
|
24
|
+
Defaults to: `lambda img_itk: sitk.OtsuThreshold(img_itk, 0, 1, 200)`.
|
|
25
|
+
n_max_iterations (Optional[int], optional):
|
|
26
|
+
Maximum number of iterations for bias field correction.
|
|
27
|
+
n_fitting_levels (int, optional):
|
|
28
|
+
Number of fitting levels. Default is 3.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
if mask_func is None:
|
|
32
|
+
mask_func = lambda img_itk: sitk.OtsuThreshold(img_itk, 0, 1, 200)
|
|
33
|
+
self.mask_func = mask_func
|
|
34
|
+
self.n_max_iterations = n_max_iterations
|
|
35
|
+
self.n_fitting_levels = n_fitting_levels
|
|
36
|
+
|
|
37
|
+
def compute_mask(self, img_itk: sitk.Image) -> sitk.Image:
|
|
38
|
+
"""
|
|
39
|
+
Compute the mask for the input image using the provided mask function.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
img_itk (SimpleITK.Image): The input image in SimpleITK format.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
SimpleITK.Image: The computed mask.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
return self.mask_func(img_itk)
|
|
49
|
+
|
|
50
|
+
def correct(
|
|
51
|
+
self,
|
|
52
|
+
input_img_path: Union[str, Path],
|
|
53
|
+
output_img_path: Union[str, Path],
|
|
54
|
+
) -> None:
|
|
55
|
+
"""
|
|
56
|
+
Correct the bias field of the input image using SimpleITK.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
input_img_path (Union[str, Path]): Path to the input image.
|
|
60
|
+
output_img_path (Union[str, Path]): Path where the corrected image will be saved.
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
None
|
|
64
|
+
"""
|
|
65
|
+
img_itk = sitk.ReadImage(str(input_img_path))
|
|
66
|
+
|
|
67
|
+
mask_itk = self.compute_mask(img_itk)
|
|
68
|
+
|
|
69
|
+
corrector = sitk.N4BiasFieldCorrectionImageFilter()
|
|
70
|
+
if self.n_max_iterations is not None:
|
|
71
|
+
corrector.SetMaximumNumberOfIterations(
|
|
72
|
+
[self.n_max_iterations] * self.n_fitting_levels
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
corrected_img = corrector.Execute(img_itk, mask_itk)
|
|
76
|
+
corrected_img = sitk.GetArrayFromImage(corrected_img)
|
|
77
|
+
|
|
78
|
+
write_image(
|
|
79
|
+
input_array=corrected_img,
|
|
80
|
+
output_path=str(output_img_path),
|
|
81
|
+
reference_path=str(input_img_path),
|
|
82
|
+
)
|
{brainles_preprocessing-0.4.0 → brainles_preprocessing-0.5.0}/brainles_preprocessing/preprocessor.py
RENAMED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import logging
|
|
2
1
|
import os
|
|
3
2
|
import shutil
|
|
4
|
-
import signal
|
|
5
3
|
import subprocess
|
|
6
|
-
import sys
|
|
7
4
|
import tempfile
|
|
8
|
-
import
|
|
9
|
-
from
|
|
5
|
+
import warnings
|
|
6
|
+
from collections import Counter
|
|
10
7
|
from functools import wraps
|
|
11
8
|
from pathlib import Path
|
|
12
9
|
from typing import List, Optional, Union
|
|
13
|
-
import warnings
|
|
14
10
|
|
|
11
|
+
from brainles_preprocessing.brain_extraction.brain_extractor import (
|
|
12
|
+
BrainExtractor,
|
|
13
|
+
HDBetExtractor,
|
|
14
|
+
)
|
|
15
15
|
from brainles_preprocessing.constants import Atlas, PreprocessorSteps
|
|
16
16
|
from brainles_preprocessing.defacing import Defacer, QuickshearDefacer
|
|
17
|
+
from brainles_preprocessing.modality import CenterModality, Modality
|
|
18
|
+
from brainles_preprocessing.n4_bias_correction import (
|
|
19
|
+
N4BiasCorrector,
|
|
20
|
+
SitkN4BiasCorrector,
|
|
21
|
+
)
|
|
22
|
+
from brainles_preprocessing.registration import ANTsRegistrator
|
|
23
|
+
from brainles_preprocessing.registration.registrator import Registrator
|
|
24
|
+
from brainles_preprocessing.utils.logging_utils import LoggingManager
|
|
17
25
|
from brainles_preprocessing.utils.zenodo import verify_or_download_atlases
|
|
18
26
|
|
|
19
|
-
from .brain_extraction.brain_extractor import BrainExtractor, HDBetExtractor
|
|
20
|
-
from .modality import Modality, CenterModality
|
|
21
|
-
from .registration import ANTsRegistrator
|
|
22
|
-
from .registration.registrator import Registrator
|
|
23
|
-
|
|
24
|
-
from .utils.logging_utils import LoggingManager
|
|
25
|
-
|
|
26
27
|
logging_man = LoggingManager(name=__name__)
|
|
27
28
|
logger = logging_man.get_logger()
|
|
28
29
|
|
|
@@ -38,6 +39,7 @@ class Preprocessor:
|
|
|
38
39
|
brain_extractor (Optional[BrainExtractor]): The brain extractor object for brain extraction.
|
|
39
40
|
defacer (Optional[Defacer]): The defacer object for defacing images.
|
|
40
41
|
atlas_image_path (Optional[str or Path]): Path to the atlas image for registration (default is the T1 atlas).
|
|
42
|
+
n4_bias_corrector (Optional[N4BiasCorrector]): The N4 bias corrector object for bias field correction. Defaults to SitkN4BiasCorrector with Otsu Thresholding.
|
|
41
43
|
temp_folder (Optional[str or Path]): Path to a folder for storing intermediate results.
|
|
42
44
|
use_gpu (Optional[bool]): Use GPU for processing if True, CPU if False, or automatically detect if None.
|
|
43
45
|
limit_cuda_visible_devices (Optional[str]): Limit CUDA visible devices to a specific GPU ID.
|
|
@@ -52,6 +54,7 @@ class Preprocessor:
|
|
|
52
54
|
brain_extractor: Optional[BrainExtractor] = None,
|
|
53
55
|
defacer: Optional[Defacer] = None,
|
|
54
56
|
atlas_image_path: Union[str, Path, Atlas] = Atlas.BRATS_SRI24,
|
|
57
|
+
n4_bias_corrector: Optional[N4BiasCorrector] = None,
|
|
55
58
|
temp_folder: Optional[Union[str, Path]] = None,
|
|
56
59
|
use_gpu: Optional[bool] = None,
|
|
57
60
|
limit_cuda_visible_devices: Optional[str] = None,
|
|
@@ -68,12 +71,18 @@ class Preprocessor:
|
|
|
68
71
|
self.center_modality = center_modality
|
|
69
72
|
self.moving_modalities = moving_modalities
|
|
70
73
|
|
|
74
|
+
self._check_for_name_conflicts()
|
|
75
|
+
|
|
71
76
|
if isinstance(atlas_image_path, Atlas):
|
|
72
77
|
atlas_folder = verify_or_download_atlases()
|
|
73
78
|
self.atlas_image_path = atlas_folder / atlas_image_path.value
|
|
74
79
|
else:
|
|
75
80
|
self.atlas_image_path = Path(atlas_image_path)
|
|
76
81
|
|
|
82
|
+
if n4_bias_corrector is None:
|
|
83
|
+
n4_bias_corrector = SitkN4BiasCorrector()
|
|
84
|
+
self.n4_bias_corrector = n4_bias_corrector
|
|
85
|
+
|
|
77
86
|
self.registrator = registrator
|
|
78
87
|
if self.registrator is None:
|
|
79
88
|
logger.warning(
|
|
@@ -97,6 +106,19 @@ class Preprocessor:
|
|
|
97
106
|
storage = tempfile.TemporaryDirectory()
|
|
98
107
|
self.temp_folder = Path(storage.name)
|
|
99
108
|
|
|
109
|
+
def _check_for_name_conflicts(self):
|
|
110
|
+
"""
|
|
111
|
+
Checks for name conflicts in the provided modalities.
|
|
112
|
+
|
|
113
|
+
Raises:
|
|
114
|
+
ValueError: If any modality name is non-unique.
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
name_counts = Counter(mod.modality_name for mod in self.all_modalities)
|
|
118
|
+
duplicates = [name for name, count in name_counts.items() if count > 1]
|
|
119
|
+
if duplicates:
|
|
120
|
+
raise ValueError(f"Duplicate modality names found: {', '.join(duplicates)}")
|
|
121
|
+
|
|
100
122
|
def _configure_gpu(
|
|
101
123
|
self, use_gpu: Optional[bool], limit_cuda_visible_devices: Optional[str] = None
|
|
102
124
|
) -> None:
|
|
@@ -162,6 +184,7 @@ class Preprocessor:
|
|
|
162
184
|
save_dir_coregistration: Optional[Union[str, Path]] = None,
|
|
163
185
|
save_dir_atlas_registration: Optional[Union[str, Path]] = None,
|
|
164
186
|
save_dir_atlas_correction: Optional[Union[str, Path]] = None,
|
|
187
|
+
save_dir_n4_bias_correction: Optional[Union[str, Path]] = None,
|
|
165
188
|
save_dir_brain_extraction: Optional[Union[str, Path]] = None,
|
|
166
189
|
save_dir_defacing: Optional[Union[str, Path]] = None,
|
|
167
190
|
save_dir_transformations: Optional[Union[str, Path]] = None,
|
|
@@ -175,6 +198,7 @@ class Preprocessor:
|
|
|
175
198
|
save_dir_coregistration (str or Path, optional): Directory path to save intermediate coregistration results.
|
|
176
199
|
save_dir_atlas_registration (str or Path, optional): Directory path to save intermediate atlas registration results.
|
|
177
200
|
save_dir_atlas_correction (str or Path, optional): Directory path to save intermediate atlas correction results.
|
|
201
|
+
save_dir_n4_bias_correction (str or Path, optional): Directory path to save intermediate N4 bias correction results.
|
|
178
202
|
save_dir_brain_extraction (str or Path, optional): Directory path to save intermediate brain extraction results.
|
|
179
203
|
save_dir_defacing (str or Path, optional): Directory path to save intermediate defacing results.
|
|
180
204
|
save_dir_transformations (str or Path, optional): Directory path to save transformation matrices. Defaults to None.
|
|
@@ -184,9 +208,10 @@ class Preprocessor:
|
|
|
184
208
|
|
|
185
209
|
1. Co-registration: Aligning moving modalities to the central modality.
|
|
186
210
|
2. Atlas Registration: Aligning the central modality to a predefined atlas.
|
|
187
|
-
3. Atlas Correction: Applying additional correction in atlas space if specified.
|
|
188
|
-
4.
|
|
189
|
-
5.
|
|
211
|
+
3. (Optional) Atlas Correction: Applying additional correction in atlas space if specified.
|
|
212
|
+
4. (Optional) N4 Bias Correction: Applying N4 bias field correction if specified.
|
|
213
|
+
5. Brain Extraction: Optionally extracting brain regions using specified masks. Only executed if any modality requires a brain extraction output (or a defacing output that requires prior brain extraction).
|
|
214
|
+
6. Defacing: Optionally deface images to remove facial features. Only executed if any modality requires a defacing output.
|
|
190
215
|
|
|
191
216
|
Results are saved in the specified directories, allowing for modular and configurable output storage.
|
|
192
217
|
"""
|
|
@@ -226,6 +251,12 @@ class Preprocessor:
|
|
|
226
251
|
save_dir_atlas_correction=save_dir_atlas_correction,
|
|
227
252
|
)
|
|
228
253
|
|
|
254
|
+
# Optional: N4 bias correction
|
|
255
|
+
logger.info(f"{' Checking optional N4 bias correction ':-^80}")
|
|
256
|
+
self.run_n4_bias_correction(
|
|
257
|
+
save_dir_n4_bias_correction=save_dir_n4_bias_correction,
|
|
258
|
+
)
|
|
259
|
+
|
|
229
260
|
# Now we save images that are not skullstripped (current image = atlas registered or atlas registered + corrected)
|
|
230
261
|
logger.info("Saving non skull-stripped images...")
|
|
231
262
|
for modality in self.all_modalities:
|
|
@@ -412,6 +443,48 @@ class Preprocessor:
|
|
|
412
443
|
save_dir=save_dir_atlas_correction,
|
|
413
444
|
)
|
|
414
445
|
|
|
446
|
+
def run_n4_bias_correction(
|
|
447
|
+
self,
|
|
448
|
+
save_dir_n4_bias_correction: Optional[Union[str, Path]] = None,
|
|
449
|
+
) -> None:
|
|
450
|
+
"""
|
|
451
|
+
Apply optional N4 bias correction to modalities.
|
|
452
|
+
|
|
453
|
+
Args:
|
|
454
|
+
save_dir_n4_bias_correction (Optional[Union[str, Path]], optional): Directory path to save intermediate N4 bias correction results. Defaults to None.
|
|
455
|
+
"""
|
|
456
|
+
|
|
457
|
+
n4_bias_correction_dir = self.temp_folder / "n4-bias-correction"
|
|
458
|
+
n4_bias_correction_dir.mkdir(exist_ok=True, parents=True)
|
|
459
|
+
|
|
460
|
+
for modality in self.all_modalities:
|
|
461
|
+
if modality.n4_bias_correction:
|
|
462
|
+
logger.info(
|
|
463
|
+
f"Applying optional N4 bias correction for modality {modality.modality_name}"
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
output_path = (
|
|
467
|
+
n4_bias_correction_dir
|
|
468
|
+
/ f"N4_bias_corrected__{modality.modality_name}.nii.gz"
|
|
469
|
+
)
|
|
470
|
+
|
|
471
|
+
self.n4_bias_corrector.correct(
|
|
472
|
+
input_img_path=str(modality.current),
|
|
473
|
+
output_img_path=str(output_path),
|
|
474
|
+
)
|
|
475
|
+
|
|
476
|
+
modality.steps[PreprocessorSteps.N4_BIAS_CORRECTED] = output_path
|
|
477
|
+
modality.current = output_path
|
|
478
|
+
else:
|
|
479
|
+
logger.info(
|
|
480
|
+
f"Skipping optional N4 bias correction for Modality {modality.modality_name}."
|
|
481
|
+
)
|
|
482
|
+
|
|
483
|
+
self._save_output(
|
|
484
|
+
src=n4_bias_correction_dir,
|
|
485
|
+
save_dir=save_dir_n4_bias_correction,
|
|
486
|
+
)
|
|
487
|
+
|
|
415
488
|
def run_brain_extraction(
|
|
416
489
|
self, save_dir_brain_extraction: Optional[Union[str, Path]] = None
|
|
417
490
|
) -> None:
|
|
@@ -142,7 +142,7 @@ class ANTsRegistrator(Registrator):
|
|
|
142
142
|
transformed_image_path: Union[str, Path],
|
|
143
143
|
matrix_path: str | Path | List[str | Path],
|
|
144
144
|
log_file_path: Union[str, Path],
|
|
145
|
-
interpolator: str = "
|
|
145
|
+
interpolator: str = "nearestNeighbor",
|
|
146
146
|
**kwargs,
|
|
147
147
|
) -> None:
|
|
148
148
|
"""
|
|
@@ -154,7 +154,7 @@ class ANTsRegistrator(Registrator):
|
|
|
154
154
|
transformed_image_path (str or Path): Path to the transformed image (output).
|
|
155
155
|
matrix_path (str or Path or List[str | Path]): Path to the transformation matrix or a list of matrices.
|
|
156
156
|
log_file_path (str or Path): Path to the log file.
|
|
157
|
-
interpolator (str): Interpolator to use for the transformation. Default is '
|
|
157
|
+
interpolator (str): Interpolator to use for the transformation. Default is 'nearestNeighbor'.
|
|
158
158
|
**kwargs: Additional transformation parameters to update the instantiated defaults.
|
|
159
159
|
Raises:
|
|
160
160
|
AssertionError: If the interpolator is not valid.
|
|
@@ -231,7 +231,7 @@ class ANTsRegistrator(Registrator):
|
|
|
231
231
|
transformed_image_path: Union[str, Path],
|
|
232
232
|
matrix_path: str | Path | List[str | Path],
|
|
233
233
|
log_file_path: Union[str, Path],
|
|
234
|
-
interpolator: str = "
|
|
234
|
+
interpolator: str = "nearestNeighbor",
|
|
235
235
|
**kwargs,
|
|
236
236
|
) -> None:
|
|
237
237
|
"""
|
|
@@ -243,7 +243,7 @@ class ANTsRegistrator(Registrator):
|
|
|
243
243
|
transformed_image_path (str or Path): Path to the transformed image (output).
|
|
244
244
|
matrix_path (str or Path): Path to the transformation matrix.
|
|
245
245
|
log_file_path (str or Path): Path to the log file.
|
|
246
|
-
interpolator (str): Interpolator to use for the transformation. Default is '
|
|
246
|
+
interpolator (str): Interpolator to use for the transformation. Default is 'nearestNeighbor'.
|
|
247
247
|
**kwargs: Additional transformation parameters to update the instantiated defaults.
|
|
248
248
|
"""
|
|
249
249
|
if not isinstance(matrix_path, list):
|
|
File without changes
|
|
@@ -150,7 +150,7 @@ class NiftyRegRegistrator(Registrator):
|
|
|
150
150
|
transformed_image_path: str,
|
|
151
151
|
matrix_path: str | Path | List[str | Path],
|
|
152
152
|
log_file_path: str,
|
|
153
|
-
interpolator: str = "
|
|
153
|
+
interpolator: str = "0",
|
|
154
154
|
**kwargs: dict,
|
|
155
155
|
) -> None:
|
|
156
156
|
"""
|
|
@@ -226,7 +226,7 @@ class NiftyRegRegistrator(Registrator):
|
|
|
226
226
|
transformed_image_path: str,
|
|
227
227
|
matrix_path: List[str | Path],
|
|
228
228
|
log_file_path: str,
|
|
229
|
-
interpolator: str = "
|
|
229
|
+
interpolator: str = "0",
|
|
230
230
|
) -> None:
|
|
231
231
|
"""
|
|
232
232
|
Apply inverse transformation using NiftyReg.
|