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

torchio.transforms.preprocessing.label.contour   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Contour.apply_transform() 0 8 2
A Contour.__init__() 0 3 1
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