Total Complexity | 2 |
Total Lines | 21 |
Duplicated Lines | 0 % |
Changes | 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 apply_transform(self, subject): |
||
14 | for image in self.get_images(subject): |
||
15 | assert image.data.ndim == 4 and image.data.shape[0] == 1 |
||
16 | sitk_image = image.as_sitk() |
||
17 | contour = sitk.BinaryContour(sitk_image) |
||
18 | tensor, _ = self.sitk_to_nib(contour) |
||
19 | image.set_data(tensor) |
||
20 | return subject |
||
21 |