예제 #1
0
    def __getitem__(self, idx):
        datamap = self.datamap_list[idx]
        if datamap[0]:
            label, data_idx, aug_idx = datamap
            data_path = self.positive_list[data_idx]
            volume_overbound = np.load(data_path)
            volume_fitted = da.extract_augment_random(
                aug_idx, volume_overbound, self.data_size,
                self.translation_num, self.translation_range,
                self.rotation_num, self.flip_num)
        else:
            label, data_idx = datamap
            data_path = self.negative_list[data_idx]
            volume_fitted = np.load(data_path)
            if np.linalg.norm(np.int_(volume_fitted.shape) -
                              self.data_size) != 0:
                volume_fitted = mt.local_crop(
                    volume_fitted,
                    np.rint(np.array(volume_fitted.shape) / 2).astype(int),
                    self.data_size
                )  #the sample should be cropped to fit the data size

        #volume = volume_fitted + np.random.random_sample(volume_fitted.shape) * random.choice(self.noise_range)
        volume = da.add_noise(volume_fitted, self.noise_range)
        if self.mode not in self.norm_mode_dict.keys():
            norm_mode = "CT_lung"
        else:
            norm_mode = self.norm_mode_dict[self.mode]
        volume = self.data_preprocess(volume, norm_mode, num_channels=1)
        '''
		volume_normalized = mt.medical_normalization(volume_fitted, input_copy=False)
		volume_noisy = volume_normalized + np.random.random_sample(volume_normalized.shape) * random.choice(self.noise_range)
		volume_reshaped = volume_noisy.reshape(1, volume_noisy.shape[0], volume_noisy.shape[1], volume_noisy.shape[2])
		volume = torch.from_numpy(volume_reshaped).float()
		'''
        output = {'data': volume, 'label': label}
        if self.file_retrieval:
            output['path'] = data_path
            #return {'data': volume, 'label': label, 'path': data_path}
        #else: return {'data': volume, 'label': label}
        return output
예제 #2
0
     elif pfile.split('/')[0].find("tianchi") >= 0:
         patient_uid, nodule_diameter = mt.get_luna_annotation_informations(
             pfile, annotation2)
     else:
         patient_uid = mt.get_volume_informations(pfile)[0]
         nodule_diameter = 0
     data_volume = da.extract_volumes(
         data_volume,
         np.int_([REGION_SIZE, REGION_SIZE, REGION_SIZE]),
         nodule_diameter=nodule_diameter,
         scale_augment=AUGMENTATION,
         translation_augment=AUGMENTATION,
         rotation_augment=AUGMENTATION)
 else:
     data_volume = mt.local_crop(
         data_volume,
         np.rint(np.array(data_volume.shape) /
                 2).astype(int), REGION_SIZE)
     data_volume = data_volume.reshape(
         (1, data_volume.shape[0], data_volume.shape[1],
          data_volume.shape[2]))
 data_label = np.zeros(shape=(data_volume.shape[0], 2),
                       dtype=float)
 data_label[:, 1 - int(isnodule)] = 1
 if "data_volumes" not in dir():
     data_volumes = data_volume
     data_labels = data_label
 else:
     data_volumes = np.concatenate(
         (data_volumes, data_volume), axis=0)
     data_labels = np.concatenate((data_labels, data_label),
                                  axis=0)