2 Copyright (c) 2019 Intel Corporation
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
21 from .base_representation import BaseRepresentation
22 from ..data_readers import BaseReader
25 class GTMaskLoader(Enum):
32 class SegmentationRepresentation(BaseRepresentation):
36 class SegmentationAnnotation(SegmentationRepresentation):
38 GTMaskLoader.PILLOW: 'pillow_imread',
39 GTMaskLoader.OPENCV: 'opencv_imread',
40 GTMaskLoader.SCIPY: 'scipy_imread',
41 GTMaskLoader.NIFTI: 'nifti_reader'
44 def __init__(self, identifier, path_to_mask, mask_loader=GTMaskLoader.PILLOW):
47 identifier: object identifier (e.g. image name).
48 path_to_mask: path where segmentation mask should be loaded from. The path is relative to data source.
49 mask_loader: back-end, used to load segmentation masks.
52 super().__init__(identifier)
53 self._mask_path = path_to_mask
54 self._mask_loader = mask_loader
59 return self._mask if self._mask is not None else self._load_mask()
62 def mask(self, value):
66 loader = BaseReader.provide(self.LOADERS.get(self._mask_loader))
67 if self._mask is None:
68 mask = loader(self._mask_path, self.metadata['data_source'])
69 return mask.astype(np.uint8)
74 class SegmentationPrediction(SegmentationRepresentation):
75 def __init__(self, identifiers, mask):
78 identifiers: object identifier (e.g. image name).
79 mask: array with shape (n_classes, height, width) of probabilities at each location.
82 super().__init__(identifiers)
86 class BrainTumorSegmentationAnnotation(SegmentationAnnotation):
87 def __init__(self, identifier, path_to_mask):
88 super().__init__(identifier, path_to_mask, GTMaskLoader.NIFTI)
90 class BrainTumorSegmentationPrediction(SegmentationPrediction):