a b/ants/math/image_similarity.py
1
2
3
__all__ = ['image_similarity']
4
5
import ants
6
from ants.decorators import image_method
7
8
@image_method
9
def image_similarity(fixed_image, moving_image, metric_type='MeanSquares',
10
                    fixed_mask=None, moving_mask=None,
11
                    sampling_strategy='regular', sampling_percentage=1.):
12
    """
13
    Measure similarity between two images.
14
    NOTE: Similarity is actually returned as distance (i.e. dissimilarity)
15
    per ITK/ANTs convention. E.g. using Correlation metric, the similarity
16
    of an image with itself returns -1.
17
18
    ANTsR function: `imageSimilarity`
19
20
    Arguments
21
    ---------
22
    fixed : ANTsImage
23
        the fixed image
24
25
    moving : ANTsImage
26
        the moving image
27
28
    metric_type : string
29
        image metric to calculate
30
            MeanSquares
31
            Correlation
32
            ANTSNeighborhoodCorrelation
33
            MattesMutualInformation
34
            JointHistogramMutualInformation
35
            Demons
36
37
    fixed_mask : ANTsImage (optional)
38
        mask for the fixed image
39
40
    moving_mask : ANTsImage (optional)
41
        mask for the moving image
42
43
    sampling_strategy : string (optional)
44
        sampling strategy, default is full sampling
45
            None (Full sampling)
46
            random
47
            regular
48
49
    sampling_percentage : scalar
50
        percentage of data to sample when calculating metric
51
        Must be between 0 and 1
52
53
    Returns
54
    -------
55
    scalar
56
57
    Example
58
    -------
59
    >>> import ants
60
    >>> x = ants.image_read(ants.get_ants_data('r16'))
61
    >>> y = ants.image_read(ants.get_ants_data('r30'))
62
    >>> metric = ants.image_similarity(x,y,metric_type='MeanSquares')
63
    """
64
    metric = ants.create_ants_metric(fixed_image, moving_image, metric_type, fixed_mask,
65
                        moving_mask, sampling_strategy, sampling_percentage)
66
    return metric.get_value()
67