Exemplo n.º 1
0
    def load_channels(self, normalize=False):

        modalities = []
        modalities.append(nib.load(self.FLAIR_FILE))
        modalities.append(nib.load(self.T1_FILE))
        modalities.append(nib.load(self.T1c_FILE))
        modalities.append(nib.load(self.T2_FILE))

        channels = np.zeros(modalities[0].shape + (4, ), dtype=np.float32)

        if normalize:
            mask = self.load_ROI_mask()

        for index_mod, mod in enumerate(modalities):
            if self.data_augmentation_flag:
                channels[:, :, :,
                         index_mod] = flip_plane(np.asarray(mod.dataobj),
                                                 plane=self.data_augmentation)
            else:
                channels[:, :, :, index_mod] = np.asarray(mod.dataobj)

            if normalize:
                channels[:, :, :,
                         index_mod] = normalize_image(channels[:, :, :,
                                                               index_mod],
                                                      mask=mask)

        return channels
Exemplo n.º 2
0
 def load_labels(self):
     labels_proxy = nib.load(self.GT_FILE)
     if self.data_augmentation:
         labels = flip_plane(np.asarray(labels_proxy.dataobj))
     else:
         labels = np.asarray(labels_proxy.dataobj)
     labels[np.where(labels == 2)] = 0  # To get rid of other pathologies
     return labels
Exemplo n.º 3
0
    def load_ROI_mask(self):

        roimask_proxy = nib.load(self.ROIMASK_FILE)
        if self.data_augmentation:
            mask = flip_plane(np.asarray(roimask_proxy.dataobj))
        else:
            mask = np.asarray(roimask_proxy.dataobj)
        return mask.astype('bool')
Exemplo n.º 4
0
    def load_tumor_mask(self):
        tumormask_proxy = nib.load(self.TUMORMASK_FILE)
        if self.data_augmentation_flag:
            mask = flip_plane(np.asarray(tumormask_proxy.dataobj),
                              plane=self.data_augmentation)
        else:
            mask = np.asarray(tumormask_proxy.dataobj)

        return mask.astype('bool')
Exemplo n.º 5
0
    def load_labels(self):
        labels_proxy = nib.load(self.GT_FILE)

        if self.data_augmentation_flag:
            labels = flip_plane(np.squeeze(np.asarray(labels_proxy.dataobj)),
                                plane=self.data_augmentation)
        else:
            labels = np.squeeze(np.asarray(labels_proxy.dataobj))

        return labels
Exemplo n.º 6
0
    def load_labels(self):
        labels_proxy = nib.load(self.GT_FILE)

        if self.data_augmentation:
            labels = flip_plane(np.asarray(labels_proxy.dataobj),
                                plane=self.data_augmentation)
        else:
            labels = np.asarray(labels_proxy.dataobj)

        unique_labels = np.unique(labels)
        unique_labels = np.sort(unique_labels)
        for it_u_l, u_l in enumerate(unique_labels):
            labels[np.where(labels == u_l)] = it_u_l
        return labels