diff --git a/brainreg/backend/niftyreg/run.py b/brainreg/backend/niftyreg/run.py index 82713fb..6b3d7c4 100644 --- a/brainreg/backend/niftyreg/run.py +++ b/brainreg/backend/niftyreg/run.py @@ -42,6 +42,7 @@ def run_niftyreg( DATA_ORIENTATION, ATLAS_ORIENTATION, niftyreg_args, + preprocessing_args, scaling, load_parallel, sort_input_file, @@ -78,7 +79,7 @@ def run_niftyreg( paths.downsampled_brain_path, ) - target_brain = preprocess.filter_image(target_brain) + target_brain = preprocess.filter_image(target_brain, preprocessing_args) save_nii( target_brain, atlas.resolution, niftyreg_paths.downsampled_filtered ) diff --git a/brainreg/cli.py b/brainreg/cli.py index 9c40f68..22932ae 100644 --- a/brainreg/cli.py +++ b/brainreg/cli.py @@ -28,6 +28,7 @@ def register_cli_parser(): parser = pixel_parser(parser) parser = geometry_parser(parser) parser = misc_parse(parser) + parser = preprocessing_parser(parser) return parser @@ -177,6 +178,24 @@ def geometry_parser(parser): return parser +def preprocessing_parser(parser): + preprocessing_opt_parser = parser.add_argument_group( + "Pre-processing options" + ) + + preprocessing_opt_parser.add_argument( + "--pre-processing", + dest="preprocessing", + type=str, + default="default", + required=False, + help="Pre-processing method to be applied before registration. " + "Possible values: skip, default.", + ) + + return parser + + def prep_registration(args): logging.debug("Making registration directory") ensure_directory_exists(args.brainreg_directory) @@ -219,6 +238,7 @@ def main(): paths, args.voxel_sizes, arg_groups["NiftyReg registration backend options"], + arg_groups["Pre-processing options"], sort_input_file=args.sort_input_file, n_free_cpus=args.n_free_cpus, additional_images_downsample=additional_images_downsample, diff --git a/brainreg/main.py b/brainreg/main.py index 820f098..10bcc3b 100644 --- a/brainreg/main.py +++ b/brainreg/main.py @@ -17,6 +17,7 @@ def main( paths, voxel_sizes, niftyreg_args, + preprocessing_args, n_free_cpus=2, sort_input_file=False, additional_images_downsample=None, @@ -70,6 +71,7 @@ def main( data_orientation, atlas.metadata["orientation"], niftyreg_args, + preprocessing_args, scaling, load_parallel, sort_input_file, diff --git a/brainreg/utils/preprocess.py b/brainreg/utils/preprocess.py index 3bb3690..5cc6a60 100644 --- a/brainreg/utils/preprocess.py +++ b/brainreg/utils/preprocess.py @@ -5,15 +5,18 @@ from tqdm import trange -def filter_image(brain): +def filter_image(brain, preprocessing_args=None): """ Filter a 3D image to allow registration :return: The filtered brain :rtype: np.array """ brain = brain.astype(np.float64, copy=False) - for i in trange(brain.shape[-1], desc="filtering", unit="plane"): - brain[..., i] = filter_plane(brain[..., i]) + if preprocessing_args and preprocessing_args.preprocessing == "skip": + pass + else: # default pre-processing + for i in trange(brain.shape[-1], desc="filtering", unit="plane"): + brain[..., i] = filter_plane(brain[..., i]) brain = scale_and_convert_to_16_bits(brain) return brain