1
+ from copy import deepcopy
1
2
from pathlib import PosixPath
2
3
from typing import Optional
3
4
6
7
from rich import print
7
8
8
9
9
- def register (fixed : ANTsImage ,
10
- moving : ANTsImage ,
11
- type_of_transform : list ,
12
- outprefix : str = "" ,
13
- path : Optional [PosixPath ] = None ,
14
- mask : Optional [str ] = None ) -> dict :
10
+ def register (
11
+ fixed : ANTsImage ,
12
+ moving : ANTsImage ,
13
+ type_of_transform : list ,
14
+ outprefix : str = "" ,
15
+ path : Optional [PosixPath ] = None ,
16
+ mask : Optional [str ] = None ,
17
+ ) -> dict :
15
18
"""Registration wrapper around ANTs
16
19
17
20
Args:
@@ -28,27 +31,29 @@ def register(fixed: ANTsImage,
28
31
if mask :
29
32
mask_path = list (path .glob (mask ))
30
33
if mask_path :
31
- mask = ants .image_read (str ( mask_path [ 0 ]),
32
- pixeltype = "unsigned int" ,
33
- reorient = "LPI" )
34
+ mask = ants .image_read (
35
+ str ( mask_path [ 0 ]), pixeltype = "unsigned int" , reorient = "LPI"
36
+ )
34
37
print (f"\t Using mask { str (mask_path [0 ])} " )
35
38
else :
36
- print (
37
- "\t [bold red]Warning: no mask found. Registering without mask..."
38
- )
39
+ print ("\t [bold red]Warning: no mask found. Registering without mask..." )
39
40
40
- return ants .registration (fixed = fixed ,
41
- moving = moving ,
42
- type_of_transform = type_of_transform ,
43
- mask = mask ,
44
- outprefix = outprefix )
41
+ return ants .registration (
42
+ fixed = fixed ,
43
+ moving = moving ,
44
+ type_of_transform = type_of_transform ,
45
+ mask = mask ,
46
+ outprefix = outprefix ,
47
+ )
45
48
46
49
47
- def get_roi (registered_atlas : ANTsImage ,
48
- idx : int ,
49
- output_dir : Optional [str ] = None ,
50
- output_file : Optional [str ] = None ,
51
- save : bool = True ) -> ANTsImage :
50
+ def get_roi (
51
+ registered_atlas : ANTsImage ,
52
+ idx : int ,
53
+ output_dir : Optional [str ] = None ,
54
+ output_file : Optional [str ] = None ,
55
+ save : bool = True ,
56
+ ) -> ANTsImage :
52
57
"""Get the registered ROI from CerebrA atlas, into a
53
58
subject's native space.
54
59
@@ -64,7 +69,7 @@ def get_roi(registered_atlas: ANTsImage,
64
69
Returns:
65
70
ANTsImage: ROI in native space
66
71
"""
67
- roi = registered_atlas . copy ( )
72
+ roi = deepcopy ( registered_atlas )
68
73
roi [roi != idx ] = 0
69
74
# roi[~np.isin(roi, idx)] = 0
70
75
0 commit comments