a b/ants/ops/reflect_image.py
1
 
2
3
__all__ = ['reflect_image']
4
5
from tempfile import mktemp
6
7
import ants
8
from ants.decorators import image_method
9
from ants.internal import get_lib_fn
10
11
@image_method
12
def reflect_image(image, axis=None, tx=None, metric='mattes'):
13
    """
14
    Reflect an image along an axis
15
16
    ANTsR function: `reflectImage`
17
18
    Arguments
19
    ---------
20
    image : ANTsImage
21
        image to reflect
22
    
23
    axis : integer (optional)
24
        which dimension to reflect across, numbered from 0 to imageDimension-1
25
    
26
    tx : string (optional)
27
        transformation type to estimate after reflection
28
    
29
    metric : string  
30
        similarity metric for image registration. see antsRegistration.
31
    
32
    Returns
33
    -------
34
    ANTsImage
35
36
    Example
37
    -------
38
    >>> import ants
39
    >>> fi = ants.image_read( ants.get_ants_data('r16'), 'float' )
40
    >>> axis = 2
41
    >>> asym = ants.reflect_image(fi, axis, 'Affine')['warpedmovout']
42
    >>> asym = asym - fi
43
    """
44
    if axis is None:
45
        axis = image.dimension - 1
46
47
    if (axis > image.dimension) or (axis < 0):
48
        axis = image.dimension - 1
49
50
    rflct = mktemp(suffix='.mat')
51
52
    libfn = get_lib_fn('reflectionMatrix')
53
    libfn(image.pointer, axis, rflct)
54
55
    if tx is not None:
56
        rfi = ants.registration(image, image, type_of_transform=tx,
57
                            syn_metric=metric, outprefix=mktemp(),
58
                            initial_transform=rflct)
59
        return rfi
60
    else:
61
        return ants.apply_transforms(image, image, rflct)
62