Skip to content

Commit

Permalink
fix: missing copy method
Browse files Browse the repository at this point in the history
  • Loading branch information
clementpoiret committed Oct 29, 2024
1 parent 4e78742 commit 74efcfa
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions roiloc/registration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import deepcopy
from pathlib import PosixPath
from typing import Optional

Expand All @@ -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:
Expand All @@ -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.
Expand All @@ -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

Expand Down

0 comments on commit 74efcfa

Please sign in to comment.