44from pathlib import Path
55from typing import Dict , Optional , Union
66
7- from auxiliary .nifti . io import read_nifti , write_nifti
7+ from auxiliary .io import read_image , write_image
88
99from brainles_preprocessing .brain_extraction .brain_extractor import BrainExtractor
1010from brainles_preprocessing .constants import PreprocessorSteps
@@ -34,6 +34,7 @@ class Modality:
3434 normalized_skull_output_path (str or Path, optional): Path to save the normalized modality data with skull. Requires a normalizer.
3535 normalized_defaced_output_path (str or Path, optional): Path to save the normalized defaced modality data. Requires a normalizer.
3636 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.
3738
3839 Attributes:
3940 modality_name (str): Name of the modality.
@@ -47,6 +48,7 @@ class Modality:
4748 normalized_defaced_output_path (str or Path, optional): Path to save the normalized defaced modality data. Requires a normalizer.
4849 bet (bool): Indicates whether brain extraction is enabled.
4950 atlas_correction (bool): Indicates whether atlas correction should be performed.
51+ n4_bias_correction (bool): Indicates whether N4 bias correction should be performed.
5052 coregistration_transform_path (str or None): Path to the coregistration transformation matrix, will be set after coregistration.
5153
5254 Example:
@@ -72,13 +74,15 @@ def __init__(
7274 normalized_skull_output_path : Optional [Union [str , Path ]] = None ,
7375 normalized_defaced_output_path : Optional [Union [str , Path ]] = None ,
7476 atlas_correction : bool = True ,
77+ n4_bias_correction : bool = False ,
7578 ) -> None :
7679 # Basics
7780 self .modality_name = modality_name
7881 self .input_path = Path (input_path )
7982 self .current = self .input_path
8083 self .normalizer = normalizer
8184 self .atlas_correction = atlas_correction
85+ self .n4_bias_correction = n4_bias_correction
8286 self .transformation_paths : Dict [PreprocessorSteps , Path | None ] = {}
8387
8488 # Check that atleast one output is generated
@@ -195,12 +199,12 @@ def normalize(
195199
196200 # Normalize the image
197201 if self .normalizer :
198- image = read_nifti (str (self .current ))
202+ image = read_image (str (self .current ))
199203 normalized_image = self .normalizer .normalize (image = image )
200- write_nifti (
204+ write_image (
201205 input_array = normalized_image ,
202- output_nifti_path = str (self .current ),
203- reference_nifti_path = str (self .current ),
206+ output_path = str (self .current ),
207+ reference_path = str (self .current ),
204208 )
205209 else :
206210 logger .info ("No normalizer specified; skipping normalization." )
@@ -505,12 +509,12 @@ def save_current_image(
505509 if normalization :
506510 if self .normalizer is None :
507511 raise ValueError ("Normalizer is required for normalization." )
508- image = read_nifti (str (self .current ))
512+ image = read_image (str (self .current ))
509513 normalized_image = self .normalizer .normalize (image = image )
510- write_nifti (
514+ write_image (
511515 input_array = normalized_image ,
512- output_nifti_path = str (output_path ),
513- reference_nifti_path = str (self .current ),
516+ output_path = str (output_path ),
517+ reference_path = str (self .current ),
514518 )
515519 else :
516520 shutil .copyfile (
@@ -534,6 +538,7 @@ class CenterModality(Modality):
534538 normalized_skull_output_path (str or Path, optional): Path to save the normalized modality data with skull. Requires a normalizer.
535539 normalized_defaced_output_path (str or Path, optional): Path to save the normalized defaced modality data. Requires a normalizer.
536540 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.
537542 bet_mask_output_path (str or Path, optional): Path to save the brain extraction mask.
538543 defacing_mask_output_path (str or Path, optional): Path to save the defacing mask.
539544
@@ -549,6 +554,7 @@ class CenterModality(Modality):
549554 normalized_defaced_output_path (str or Path, optional): Path to save the normalized defaced modality data. Requires a normalizer.
550555 bet (bool): Indicates whether brain extraction is enabled.
551556 atlas_correction (bool): Indicates whether atlas correction should be performed.
557+ n4_bias_correction (bool): Indicates whether N4 bias correction should be performed.
552558 bet_mask_output_path (Path, optional): Path to save the brain extraction mask.
553559 defacing_mask_output_path (Path, optional): Path to save the defacing mask.
554560
@@ -575,6 +581,7 @@ def __init__(
575581 normalized_skull_output_path : Optional [Union [str , Path ]] = None ,
576582 normalized_defaced_output_path : Optional [Union [str , Path ]] = None ,
577583 atlas_correction : bool = True ,
584+ n4_bias_correction : bool = False ,
578585 bet_mask_output_path : Optional [Union [str , Path ]] = None ,
579586 defacing_mask_output_path : Optional [Union [str , Path ]] = None ,
580587 ) -> None :
@@ -589,6 +596,7 @@ def __init__(
589596 normalized_skull_output_path = normalized_skull_output_path ,
590597 normalized_defaced_output_path = normalized_defaced_output_path ,
591598 atlas_correction = atlas_correction ,
599+ n4_bias_correction = n4_bias_correction ,
592600 )
593601 # Only for CenterModality
594602 self .bet_mask_output_path = (
0 commit comments