| Total Complexity | 2 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Changes | 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 |