a b/ants/ops/anti_alias.py
1
"""
2
Apply anti-alias filter on a binary ANTsImage
3
"""
4
5
__all__ = ['anti_alias']
6
7
import ants
8
from ants.internal import get_lib_fn
9
from ants.decorators import image_method
10
11
@image_method
12
def anti_alias(image):
13
    """
14
    Apply Anti-Alias filter to a binary image
15
    
16
    ANTsR function: N/A
17
18
    Arguments
19
    ---------
20
    image : ANTsImage
21
        binary image to which anti-aliasing will be applied
22
23
    Returns
24
    -------
25
    ANTsImage
26
27
    Example
28
    -------
29
    >>> import ants
30
    >>> img = ants.image_read(ants.get_data('r16'))
31
    >>> mask = ants.get_mask(img)
32
    >>> mask_aa = ants.anti_alias(mask)
33
    >>> ants.plot(mask)
34
    >>> ants.plot(mask_aa)
35
    """
36
    if image.pixeltype != 'unsigned char':
37
        if image.max() > 255.:
38
            image = (image - image.max()) / (image.max() - image.min())
39
        image = image.clone('unsigned char')
40
41
    libfn = get_lib_fn('antiAlias%s' % image._libsuffix)
42
    new_ptr = libfn(image.pointer)
43
    return ants.from_pointer(new_ptr)