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

torchio.transforms.preprocessing.label.remove_labels   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A RemoveLabels.__init__() 0 13 1
A RemoveLabels.is_invertible() 0 2 1
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