diff --git a/roiloc/registration.py b/roiloc/registration.py index 0bb32d8..b411cee 100644 --- a/roiloc/registration.py +++ b/roiloc/registration.py @@ -1,3 +1,4 @@ +from copy import deepcopy from pathlib import PosixPath from typing import Optional @@ -6,12 +7,14 @@ from rich import print -def register(fixed: ANTsImage, - moving: ANTsImage, - type_of_transform: list, - outprefix: str = "", - path: Optional[PosixPath] = None, - mask: Optional[str] = None) -> dict: +def register( + fixed: ANTsImage, + moving: ANTsImage, + type_of_transform: list, + outprefix: str = "", + path: Optional[PosixPath] = None, + mask: Optional[str] = None, +) -> dict: """Registration wrapper around ANTs Args: @@ -28,27 +31,29 @@ def register(fixed: ANTsImage, if mask: mask_path = list(path.glob(mask)) if mask_path: - mask = ants.image_read(str(mask_path[0]), - pixeltype="unsigned int", - reorient="LPI") + mask = ants.image_read( + str(mask_path[0]), pixeltype="unsigned int", reorient="LPI" + ) print(f"\tUsing mask {str(mask_path[0])}") else: - print( - "\t[bold red]Warning: no mask found. Registering without mask..." - ) + print("\t[bold red]Warning: no mask found. Registering without mask...") - return ants.registration(fixed=fixed, - moving=moving, - type_of_transform=type_of_transform, - mask=mask, - outprefix=outprefix) + return ants.registration( + fixed=fixed, + moving=moving, + type_of_transform=type_of_transform, + mask=mask, + outprefix=outprefix, + ) -def get_roi(registered_atlas: ANTsImage, - idx: int, - output_dir: Optional[str] = None, - output_file: Optional[str] = None, - save: bool = True) -> ANTsImage: +def get_roi( + registered_atlas: ANTsImage, + idx: int, + output_dir: Optional[str] = None, + output_file: Optional[str] = None, + save: bool = True, +) -> ANTsImage: """Get the registered ROI from CerebrA atlas, into a subject's native space. @@ -64,7 +69,7 @@ def get_roi(registered_atlas: ANTsImage, Returns: ANTsImage: ROI in native space """ - roi = registered_atlas.copy() + roi = deepcopy(registered_atlas) roi[roi != idx] = 0 # roi[~np.isin(roi, idx)] = 0