Passed
Push — master ( b9ac52...6aebda )
by Fernando
10:37 queued 20s
created

RemoveLabels.__init__()   A

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nop 5
dl 0
loc 13
rs 9.8
c 0
b 0
f 0
1
from typing import Sequence
2
3
from ...transform import TypeMaskingMethod
4
from .remap_labels import RemapLabels
5
6
7
class RemoveLabels(RemapLabels):
8
    r"""Remove labels from a label map by remapping them to the background label.
9
10
    This transformation is not `invertible <invertibility>`_.
11
12
    Args:
13
        labels: A sequence of label integers that will be removed.
14
        background_label: integer that specifies which label is considered to be
15
            background (generally 0).
16
        masking_method: See :class:`~torchio.RemapLabels`.
17
        **kwargs: See :class:`~torchio.transforms.Transform` for additional
18
            keyword arguments.
19
    """
20
    def __init__(
21
            self,
22
            labels: Sequence[int],
23
            background_label: int = 0,
24
            masking_method: TypeMaskingMethod = None,
25
            **kwargs
26
            ):
27
        remapping = {label: background_label for label in labels}
28
        super().__init__(remapping, masking_method, **kwargs)
29
        self.labels = labels
30
        self.background_label = background_label
31
        self.masking_method = masking_method
32
        self.args_names = ('labels', 'background_label', 'masking_method',)
33
34
    def is_invertible(self):
35
        return False
36