def preprocess_Tmap(self, T1map, T2map):
     print('%%%%%%%%%%%%%%%%%%%5: ', T1map.shape)
     T1map = numpy.fliplr(numpy.flipud(T1map))
     T2map = numpy.fliplr(numpy.flipud(T2map))
     Tmap = numpy.stack((T1map, T2map), axis=0).transpose(2, 1, 0)
     Tmap = util.preprocess_tissue_property(Tmap).transpose(2, 1, 0)
     return Tmap.transpose(1, 2, 0)
Beispiel #2
0
 def preprocess_Tmap(self, T1map, T2map):
     Tmap = numpy.stack((T1map,T2map), axis=0).transpose(2,1,0)
     Tmap = util.preprocess_tissue_property(Tmap).transpose(2,1,0)
     return Tmap
Beispiel #3
0
    def initialize(self, opt):
        if opt.isTrain:
            self.augmentation = opt.augmentation
        else:
            self.augmentation = False
        # self.augmentation = False
        self.augmentation_type = 'flip'
        self.goal_type = 'dict'
        self.mask_type = opt.mask

        self.get_paths(opt)
        self.A_imgs = []
        self.B_imgs = []
        self.masks = []

        for i, A_path in enumerate(self.A_paths):
            A_path1 = A_path
            f = h5py.File(A_path1)
            A_img = f['imMRF'][0:int(opt.input_nc / 2), :, :]
            A_img = numpy.transpose(A_img)
            A_img = numpy.concatenate((A_img['real'], A_img['imag']),
                                      axis=2).astype('float32')
            # A_img = numpy.concatenate((A_img[:,:,0:int(opt.input_nc/2)],A_img[:,:,2304:2304+int(opt.input_nc/2)]), axis=2)
            f.close()

            # normalization
            if opt.data_norm == 'non':
                print("no normalization")
                pass
            else:
                start = time.time()
                t = numpy.mean(A_img**2, axis=2) * 2
                t = t[:, :, numpy.newaxis]
                A_img = A_img / (t**0.5)
                A_img = A_img / 36
                end = time.time()
                util.print_log(
                    'Time for normalizing energy: %.5fs ' % (end - start),
                    opt.file_name)

            # magnitude
            if opt.magnitude:
                ntp = int(opt.input_nc / 2)
                A_img_mag = numpy.copy(A_img[:, :, 0:ntp])
                for k in range(ntp):
                    A_img_mag[:, :, k] = (A_img[:, :, k]**2 +
                                          A_img[:, :, ntp + k]**2)**0.5
                A_img = A_img_mag

            # set background signals as zero
            # f = h5py.File(self.mask_large_paths[i])
            # mask_large = numpy.transpose(f['mask']).astype('float32')
            # f.close()
            # A_img = A_img * mask_large[:,:,numpy.newaxis]

            # load mask
            if self.mask_type == 'tight':
                f = h5py.File(self.mask_tight_paths[i])
            else:
                f = h5py.File(self.mask_large_paths[i])
            mask = numpy.transpose(f['mask']).astype('float32')
            f.close()

            # clear mask
            # mask = mask * 0 + 1

            # load ground truth
            if self.goal_type == 'densedict':
                f = h5py.File(self.goal_densedict_paths[i])
            else:
                f = h5py.File(self.goal_paths[i])
            T1 = numpy.transpose(f['t1big']).astype('float32')
            T1 = T1[:, :, numpy.newaxis]
            T2 = numpy.transpose(f['t2big']).astype('float32')
            T2 = T2[:, :, numpy.newaxis]
            B_img = numpy.concatenate((T1, T2), axis=2)
            B_img = util.preprocess_tissue_property(B_img)
            if self.goal_type == 'densedict':
                B_img = numpy.flip(B_img, (0, 1)).copy()
            f.close()

            mask = mask[:, :, numpy.newaxis]
            assert A_img.ndim == 3 and B_img.ndim == 3, "# of dim is not 3 for training image"

            if opt.set_type == 'train':
                A_img = A_img[40:216, 52:236, :]
                B_img = B_img[40:216, 52:236, :]
                mask = mask[40:216, 52:236, :]

            A_img = torch.from_numpy(A_img)
            B_img = torch.from_numpy(B_img)
            mask = torch.from_numpy(mask)

            if opt.input_nc == 2304 * 2:
                print('half float16')
                A_img = A_img.half()
                B_img = B_img.half()
                mask = mask.half()

            A_img = A_img.permute(2, 0, 1)
            B_img = B_img.permute(2, 0, 1)
            mask = mask.permute(2, 0, 1)

            self.A_imgs.append(A_img)
            self.B_imgs.append(B_img)
            self.masks.append(mask)
            print("loaded image: %s" % A_path)

        self.num_imgs = len(self.A_imgs)
        if opt.patchSize != 0:
            # self.num_patch = self.num_imgs*int((self.A_imgs[0].shape[1]*self.A_imgs[0].shape[2])/(opt.patchSize**2))
            # self.num_patch = math.ceil(self.num_patch/opt.batchSize)*opt.batchSize
            self.get_patch_pos(opt)