def datasources(self, iterator, cached):
     """
     Returns the data sources that load data.
     {
     'image:' CachedImageDataSource that loads the image files.
     'labels:' CachedImageDataSource that loads the groundtruth labels.
     'landmarks:' LandmarkDataSource that loads the landmark coordinates.
     }
     :param iterator: The dataset iterator.
     :param cached: If true, use CachedImageDataSource, else ImageDataSource.
     :return: A dict of data sources.
     """
     datasources_dict = {}
     image_data_source = CachedImageDataSource if cached else ImageDataSource
     datasources_dict['image'] = image_data_source(
         self.image_base_folder,
         '',
         '',
         '.nii.gz',
         set_zero_origin=False,
         set_identity_direction=False,
         set_identity_spacing=False,
         sitk_pixel_type=sitk.sitkInt16,
         preprocessing=self.preprocessing,
         name='image',
         parents=[iterator])
     if self.generate_landmark_mask:
         datasources_dict['landmark_mask'] = LambdaNode(
             self.landmark_mask_preprocessing,
             name='image',
             parents=[datasources_dict['image']])
     if self.generate_labels or self.generate_single_vertebrae:
         datasources_dict['labels'] = image_data_source(
             self.image_base_folder,
             '',
             '_seg',
             '.nii.gz',
             set_zero_origin=False,
             set_identity_direction=False,
             set_identity_spacing=False,
             sitk_pixel_type=sitk.sitkUInt8,
             name='labels',
             parents=[iterator])
     if self.generate_landmarks or self.generate_heatmaps or self.generate_spine_heatmap or self.generate_single_vertebrae or self.generate_single_vertebrae_heatmap or (
             self.translate_to_center_landmarks
             and not self.load_spine_landmarks):
         datasources_dict['landmarks'] = LandmarkDataSource(
             self.landmarks_file,
             self.num_landmarks,
             self.dim,
             name='landmarks',
             parents=[iterator])
     if self.load_spine_landmarks:
         datasources_dict['spine_landmarks'] = LandmarkDataSource(
             self.spine_landmarks_file,
             1,
             self.dim,
             name='spine_landmarks',
             parents=[iterator])
     return datasources_dict
Пример #2
0
    def landmark_datasources(self, iterator):
        """
        Returns all LandmarkDataSources as a dictionary. The entry 'landmark_data_source' is set to the value set in self.landmark_source.
        Other entries: 'junior_landmarks_datasource',
                       'senior_landmarks_datasource',
                       'challenge_landmarks_datasource',
                       'mean_landmarks_datasource',
                       'random_landmarks_datasource'.
        :param iterator: The iterator that is used as the parent node.
        :return: Dictionary of all LandmarkDataSources.
        """
        senior_landmarks_datasource = LandmarkDataSource(
            self.senior_point_list_file_name,
            self.num_landmarks,
            self.dim,
            parents=[iterator],
            name='senior_landmarks_datasource')
        junior_landmarks_datasource = LandmarkDataSource(
            self.junior_point_list_file_name,
            self.num_landmarks,
            self.dim,
            parents=[iterator],
            name='junior_landmarks_datasource')
        challenge_landmarks_datasource = LandmarkDataSource(
            self.challenge_point_list_file_name,
            self.num_landmarks,
            self.dim,
            parents=[iterator],
            name='challenge_landmarks_datasource')
        mean_landmarks_datasource = LambdaNode(
            lambda junior, senior: get_mean_landmark_list(junior, senior),
            parents=[junior_landmarks_datasource, senior_landmarks_datasource],
            name='mean_landmarks_datasource')
        random_landmarks_datasource = LambdaNode(
            lambda junior, senior: senior if bool_bernoulli(0.5) else junior,
            parents=[junior_landmarks_datasource, senior_landmarks_datasource],
            name='random_landmarks_datasource')
        if self.landmark_source == 'senior':
            landmark_datasource = senior_landmarks_datasource
        elif self.landmark_source == 'junior':
            landmark_datasource = junior_landmarks_datasource
        elif self.landmark_source == 'challenge':
            landmark_datasource = challenge_landmarks_datasource
        elif self.landmark_source == 'mean':
            landmark_datasource = mean_landmarks_datasource
        elif self.landmark_source == 'random':
            landmark_datasource = random_landmarks_datasource

        return {
            'junior_landmarks_datasource': junior_landmarks_datasource,
            'senior_landmarks_datasource': senior_landmarks_datasource,
            'challenge_landmarks_datasource': challenge_landmarks_datasource,
            'mean_landmarks_datasource': mean_landmarks_datasource,
            'random_landmarks_datasource': random_landmarks_datasource,
            'landmark_datasource': landmark_datasource
        }
Пример #3
0
 def data_sources(self, cached, image_extension='.mha'):
     """
     Returns the data sources that load data.
     {
     'image_datasource:' ImageDataSource that loads the image files.
     'landmarks_datasource:' LandmarkDataSource that loads the landmark coordinates.
     }
     :param cached: If true, use a CachedImageDataSource instead of an ImageDataSource.
     :param image_extension: The image extension of the input data.
     :return: A dict of data sources.
     """
     if cached:
         image_datasource = CachedImageDataSource(
             self.image_base_folder,
             '',
             '',
             image_extension,
             preprocessing=reduce_dimension,
             set_identity_spacing=True,
             cache_maxsize=16384)
     else:
         image_datasource = ImageDataSource(self.image_base_folder,
                                            '',
                                            '',
                                            image_extension,
                                            preprocessing=reduce_dimension,
                                            set_identity_spacing=True)
     landmarks_datasource = LandmarkDataSource(self.point_list_file_name,
                                               self.num_landmarks, self.dim)
     return {
         'image_datasource': image_datasource,
         'landmarks_datasource': landmarks_datasource
     }
Пример #4
0
 def datasources(self, iterator, cached):
     """
     Returns the data sources that load data.
     {
     'image:' CachedImageDataSource that loads the image files.
     'labels:' CachedImageDataSource that loads the groundtruth labels.
     'landmarks:' LandmarkDataSource that loads the landmark coordinates.
     }
     :param iterator: The dataset iterator.
     :param cached: If true, use CachedImageDataSource, else ImageDataSource.
     :return: A dict of data sources.
     """
     datasources_dict = {}
     image_data_source = CachedImageDataSource if cached else ImageDataSource
     datasources_dict['image'] = image_data_source(
         self.image_base_folder,
         '',
         '_image',
         '.mha',
         set_zero_origin=True,
         set_identity_direction=True,
         set_identity_spacing=False,
         sitk_pixel_type=sitk.sitkInt16,
         preprocessing=self.preprocessing,
         name='image',
         parents=[iterator])
     datasources_dict['landmarks'] = LandmarkDataSource(self.landmarks_file,
                                                        1,
                                                        self.dim,
                                                        name='landmarks',
                                                        parents=[iterator])
     return datasources_dict
Пример #5
0
 def datasources(self):
     """
     Returns the data sources that load data.
     {
     'image:' CachedImageDataSource that loads the image files.
     'landmarks:' LandmarkDataSource that loads the landmark coordinates.
     'mask:' CachedImageDataSource that loads the groundtruth labels.
     }
     :return: A dict of data sources.
     """
     preprocessing = lambda image: gaussian_sitk(image, self.
                                                 input_gaussian_sigma)
     image_datasource = CachedImageDataSource(self.image_base_folder,
                                              '',
                                              '_image',
                                              '.mha',
                                              preprocessing=preprocessing)
     landmark_datasource = LandmarkDataSource(self.landmarks_file, 1,
                                              self.dim)
     mask_datasource = CachedImageDataSource(self.image_base_folder,
                                             '',
                                             '_label_sorted',
                                             '.mha',
                                             sitk_pixel_type=sitk.sitkUInt8)
     return {
         'image': image_datasource,
         'landmarks': landmark_datasource,
         'mask': mask_datasource
     }
Пример #6
0
 def data_sources(self,
                  iterator,
                  cached,
                  use_landmarks=True,
                  image_extension='.nii.gz'):
     """
     Returns the data sources that load data.
     {
     'image_datasource:' ImageDataSource that loads the image files.
     'landmarks_datasource:' LandmarkDataSource that loads the landmark coordinates.
     }
     :param iterator: The iterator node object.
     :param cached: If True, use CachedImageDataSource instead of ImageDataSource.
     :param use_landmarks: If True, create a landmarks datasource.
     :param image_extension: The extension of the image files.
     :return: A dict of data sources.
     """
     if self.smoothing_sigma is not None and self.smoothing_sigma > 0:
         preprocessing = lambda x: sitk.Cast(
             gaussian(x, self.smoothing_sigma), sitk.sitkInt16)
     else:
         preprocessing = None
     if cached:
         image_datasource = CachedImageDataSource(
             self.image_base_folder,
             '',
             '',
             image_extension,
             preprocessing=preprocessing,
             cache_maxsize=25000,
             name='image_datasource',
             parents=[iterator])
     else:
         image_datasource = ImageDataSource(self.image_base_folder,
                                            '',
                                            '',
                                            image_extension,
                                            preprocessing=preprocessing,
                                            name='image_datasource',
                                            parents=[iterator])
     data_sources_dict = {}
     data_sources_dict['image_datasource'] = image_datasource
     if use_landmarks:
         landmark_datasource = LandmarkDataSource(
             self.point_list_file_name,
             self.num_landmarks,
             self.dim,
             name='landmarks_datasource',
             parents=[iterator])
         data_sources_dict['landmarks_datasource'] = landmark_datasource
     return data_sources_dict
 def datasources(self, iterator, image_cached, labels_cached, image_preprocessing, cache_size):
     """
     Returns the data sources that load data.
     {
     'image:' CachedImageDataSource that loads the image files.
     'labels:' CachedImageDataSource that loads the groundtruth labels.
     'landmarks:' LandmarkDataSource that loads the landmark coordinates.
     }
     :param iterator: The dataset iterator.
     :param cached: If true, use CachedImageDataSource, else ImageDataSource.
     :return: A dict of data sources.
     """
     datasources_dict = {}
     if image_cached:
         image_data_source = CachedImageDataSource
         image_source_kwargs = {'cache_maxsize': cache_size}
     else:
         image_data_source = ImageDataSource
         image_source_kwargs = {}
     datasources_dict['image'] = image_data_source(self.image_base_folder,
                                                   '',
                                                   '',
                                                   '.nii.gz',
                                                   set_zero_origin=False,
                                                   set_identity_direction=False,
                                                   set_identity_spacing=False,
                                                   sitk_pixel_type=sitk.sitkInt16,
                                                   preprocessing=image_preprocessing,
                                                   name='image',
                                                   parents=[iterator],
                                                   **image_source_kwargs)
     if self.generate_landmark_mask:
         datasources_dict['landmark_mask'] = LambdaNode(self.landmark_mask_preprocessing,
                                                        name='landmark_mask',
                                                        parents=[datasources_dict['image']])
     if self.generate_labels or self.generate_single_vertebrae:
         if labels_cached:
             image_data_source = CachedImageDataSource
             image_source_kwargs = {'cache_maxsize': cache_size}
         else:
             image_data_source = ImageDataSource
             image_source_kwargs = {}
         datasources_dict['labels'] = image_data_source(self.image_base_folder,
                                                        '',
                                                        '_seg',
                                                        '.nii.gz',
                                                        set_zero_origin=False,
                                                        set_identity_direction=False,
                                                        set_identity_spacing=False,
                                                        sitk_pixel_type=sitk.sitkUInt8,
                                                        name='labels',
                                                        parents=[iterator],
                                                        **image_source_kwargs)
     if self.generate_landmarks or self.generate_heatmaps or self.generate_spine_heatmap or self.generate_single_vertebrae or self.generate_single_vertebrae_heatmap or (self.translate_to_center_landmarks and not (self.load_spine_landmarks or self.load_spine_bbs)):
         datasources_dict['landmarks'] = LandmarkDataSource(self.landmarks_file,
                                                            self.num_landmarks,
                                                            self.dim,
                                                            name='landmarks',
                                                            parents=[iterator])
         datasources_dict['landmarks_bb'] = LambdaNode(self.image_landmark_bounding_box, name='landmarks_bb', parents=[datasources_dict['image'], datasources_dict['landmarks']])
         datasources_dict['landmarks_bb_start'] = LambdaNode(lambda x: x[0], name='landmarks_bb_start', parents=[datasources_dict['landmarks_bb']])
         datasources_dict['landmarks_bb_extent'] = LambdaNode(lambda x: x[1], name='landmarks_bb_extent', parents=[datasources_dict['landmarks_bb']])
     if self.load_spine_landmarks:
         datasources_dict['spine_landmarks'] = LandmarkDataSource(self.spine_landmarks_file, 1, self.dim, name='spine_landmarks', parents=[iterator])
     if self.load_spine_bbs:
         datasources_dict['spine_bb'] = LabelDatasource(self.spine_bbs_file, name='spine_landmarks', parents=[iterator])
         datasources_dict['landmarks_bb'] = LambdaNode(self.image_bounding_box, name='landmarks_bb', parents=[datasources_dict['image'], datasources_dict['spine_bb']])
         datasources_dict['landmarks_bb_start'] = LambdaNode(lambda x: x[0], name='landmarks_bb_start', parents=[datasources_dict['landmarks_bb']])
         datasources_dict['landmarks_bb_extent'] = LambdaNode(lambda x: x[1], name='landmarks_bb_extent', parents=[datasources_dict['landmarks_bb']])
     return datasources_dict