| from light_training.preprocessing.preprocessors.preprocessor_mri import MultiModalityPreprocessor | |
| import argparse | |
| data_filename = ["t2w.nii.gz", | |
| "t2f.nii.gz", | |
| "t1n.nii.gz", | |
| "t1c.nii.gz"] | |
| seg_filename = "seg.nii.gz" | |
| def _parse_spacing(s: str): | |
| parts = [p.strip() for p in s.split(",") if p.strip()] | |
| if len(parts) != 3: | |
| raise ValueError(f"output_spacing should be like '1,1,1', got: {s}") | |
| return [float(parts[0]), float(parts[1]), float(parts[2])] | |
| def main(): | |
| parser = argparse.ArgumentParser(description="BraTS2023 preprocessing (resample/normalization/cropping).") | |
| parser.add_argument( | |
| "--base_dir", | |
| type=str, | |
| default="./data/raw_data/BraTS2023/", | |
| help="Base directory that contains the BraTS2023 image_dir folder.", | |
| ) | |
| parser.add_argument( | |
| "--image_dir", | |
| type=str, | |
| default="ASNR-MICCAI-BraTS2023-GLI-Challenge-TrainingData", | |
| help="Folder name under base_dir.", | |
| ) | |
| parser.add_argument( | |
| "--output_dir", | |
| type=str, | |
| default="./data/fullres/train/", | |
| help="Output directory for preprocessed npz/npy/pkl files.", | |
| ) | |
| parser.add_argument( | |
| "--output_spacing", | |
| type=str, | |
| default="1,1,1", | |
| help="Target spacing, e.g. '1,1,1'.", | |
| ) | |
| parser.add_argument( | |
| "--num_processes", | |
| type=int, | |
| default=8, | |
| help="Number of worker processes for preprocessing.", | |
| ) | |
| parser.add_argument( | |
| "--only_plan", | |
| action="store_true", | |
| help="Only run planning (statistics) and exit.", | |
| ) | |
| parser.add_argument( | |
| "--skip_plan", | |
| action="store_true", | |
| help="Skip planning step.", | |
| ) | |
| args = parser.parse_args() | |
| preprocessor = MultiModalityPreprocessor( | |
| base_dir=args.base_dir, | |
| image_dir=args.image_dir, | |
| data_filenames=data_filename, | |
| seg_filename=seg_filename, | |
| ) | |
| if not args.skip_plan: | |
| preprocessor.run_plan() | |
| if args.only_plan: | |
| return | |
| out_spacing = _parse_spacing(args.output_spacing) | |
| preprocessor.run( | |
| output_spacing=out_spacing, | |
| output_dir=args.output_dir, | |
| all_labels=[1, 2, 3], | |
| num_processes=args.num_processes, | |
| ) | |
| if __name__ == "__main__": | |
| main() | |