Switch to unified view

a b/inst/deepbleed/preprocess/register.py
1
# @author: msharrock
2
# version: 0.0.1
3
4
"""
5
Registration methods for DeepBleed 
6
7
"""
8
import ants
9
10
def rigid(fixed, moving):
11
12
        '''
13
        Rigid Registration with ANTs
14
15
        Params:
16
                - moving: ants image, image to move when registering
17
                - fixed: ants image, template image to register to
18
19
        Outputs: 
20
                - image: registered image
21
                - transforms: transformation affine matrix
22
        '''
23
24
        kwargs = {'-n': 'nearestNeighbor'}
25
        tx = ants.registration(fixed, moving, type_of_transform='Rigid', mask=None, grad_step=0.2, flow_sigma=3, total_sigma=0, 
26
                           aff_metric='mattes', aff_sampling=64, syn_metric ='mattes',**kwargs) 
27
                        
28
        image = tx['warpedmovout']
29
        transforms = tx['fwdtransforms']
30
        return image, transforms
31
32
33
def invert(fixed, moving, transforms):
34
        '''
35
        Inverse Transform with ANTs
36
37
        Params:
38
                - image: ants image, image to revert
39
                - invtransform: affine matrix to use for inverse transform
40
        Outputs: 
41
                - image: ants image, inverted
42
        '''
43
        image = ants.apply_transforms(fixed = fixed, moving = moving, transformlist = transforms, interpolator = 'genericLabel', whichtoinvert = [True])   
44
45
        return image
46