Completed
Push — master ( daf754...bec33c )
by Fernando
08:00
created

Contour.apply_transform()   A

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
import SimpleITK as sitk
2
3
from .label_transform import LabelTransform
4
5
6
class Contour(LabelTransform):
7
    r"""Keep only the borders of each connected component in a binary image.
8
9
    Args:
10
        **kwargs: See :class:`~torchio.transforms.Transform` for additional
11
            keyword arguments.
12
    """
13
    def __init__(self, **kwargs):
14
        super().__init__(**kwargs)
15
        self.args_names = []
16
17
    def apply_transform(self, subject):
18
        for image in self.get_images(subject):
19
            assert image.data.ndim == 4 and image.data.shape[0] == 1
20
            sitk_image = image.as_sitk()
21
            contour = sitk.BinaryContour(sitk_image)
22
            tensor, _ = self.sitk_to_nib(contour)
23
            image.set_data(tensor)
24
        return subject
25