Пример #1
0
 def get_item_train(self, filename):
     images, kspaces = from_train_file_to_image_and_kspace(filename)
     real_images = np.empty_like(kspaces)
     for i, kspace in enumerate(kspaces):
         real_images[i] = ifft(kspace)
     images = images[..., None]
     real_images = real_images[..., None]
     kspaces = kspaces[..., None]
     k_shape = kspaces[0].shape
     mask = gen_mask(kspaces[0, ..., 0], accel_factor=self.af)
     fourier_mask = np.repeat(mask.astype(np.float), k_shape[0], axis=0)
     mask_batch = np.repeat(fourier_mask[None, ...], len(kspaces), axis=0)[..., None]
     kspaces *= mask_batch
     mask_batch = mask_batch[..., 0]
     if self.inner_slices is not None:
         n_slices = len(kspaces)
         slice_start = n_slices // 2 - self.inner_slices // 2
         if self.rand:
             i_slice = random.randint(slice_start, slice_start + self.inner_slices)
             selected_slices = slice(i_slice, i_slice + 1)
         else:
             selected_slices = slice(slice_start, slice_start + self.inner_slices)
         kspaces = kspaces[selected_slices]
         images = images[selected_slices]
         mask_batch = mask_batch[selected_slices]
         real_images = real_images[selected_slices]
     return ([kspaces, mask_batch], images, real_images)
Пример #2
0
 def get_item_train(self, filename):
     images, kspaces = from_train_file_to_image_and_kspace(filename)
     mask = gen_mask(kspaces[0], accel_factor=self.af)
     fourier_mask = np.repeat(mask.astype(np.float), kspaces[0].shape[0], axis=0)
     img_batch = list()
     zero_img_batch = list()
     if self.norm and self.mode == 'validation':
         means = list()
         stddevs = list()
     for kspace, image in zip(kspaces, images):
         zero_filled_rec = zero_filled(kspace * fourier_mask)
         if self.norm:
             zero_filled_rec, mean, std = normalize_instance(zero_filled_rec, eps=1e-11)
             image = normalize(image, mean, std, eps=1e-11)
             if self.mode == 'validation':
                 means.append(mean)
                 stddevs.append(std)
         zero_filled_rec = zero_filled_rec[:, :, None]
         zero_img_batch.append(zero_filled_rec)
         image = image[..., None]
         img_batch.append(image)
     zero_img_batch = np.array(zero_img_batch)
     img_batch = np.array(img_batch)
     if self.norm and self.mode == 'validation':
         return zero_img_batch, img_batch, means, stddevs
     else:
         return (zero_img_batch, img_batch)
Пример #3
0
 def get_item_train(self, filename):
     images, kspaces = from_train_file_to_image_and_kspace(filename)
     mask = gen_mask(kspaces[0], accel_factor=self.af)
     fourier_mask = np.repeat(mask.astype(np.float), kspaces[0].shape[0], axis=0)
     img_batch = list()
     z_kspace_batch = list()
     to_pad = type(self).pad - kspaces.shape[2]
     pad_seq = [(0, 0), (to_pad // 2, to_pad // 2)]
     if self.norm and self.mode == 'validation':
         means = list()
         stddevs = list()
     for kspace, image in zip(kspaces, images):
         zero_filled_rec = ifft(kspace * fourier_mask)
         if self.norm:
             zero_filled_rec, mean, std = normalize_instance(zero_filled_rec, eps=1e-11)
             image = normalize(image, mean, std, eps=1e-11)
             if self.mode == 'validation':
                 means.append(mean)
                 stddevs.append(std)
         zero_filled_rec = np.pad(zero_filled_rec, pad_seq, mode='constant')
         z_kspace = fft(zero_filled_rec)
         z_kspace = z_kspace[:, :, None]
         z_kspace_batch.append(z_kspace)
         image = np.pad(image, pad_seq, mode='constant')
         image = image[..., None]
         img_batch.append(image)
     z_kspace_batch = np.array(z_kspace_batch)
     img_batch = np.array(img_batch)
     if self.norm and self.mode == 'validation':
         return z_kspace_batch, img_batch, means, stddevs
     else:
         return (z_kspace_batch, img_batch)
Пример #4
0
 def get_item_train(self, filename):
     kspaces = from_file_to_kspace(filename)
     k_shape = kspaces[0].shape
     mask = gen_mask(kspaces[0], accel_factor=self.af)
     fourier_mask = np.repeat(mask.astype(np.float), k_shape[0], axis=0)
     img_batch = list()
     kspace_batch = list()
     mask_batch = list()
     for kspace in kspaces:
         masked_kspace = kspace * fourier_mask
         masked_kspace *= np.sqrt(np.prod(k_shape))
         shifted_masked_kspace = np.fft.ifftshift(masked_kspace)
         shifted_mask = np.fft.ifftshift(fourier_mask)
         image = np.abs(ifft(kspace))
         image_shifted = np.fft.fftshift(image)
         image_shifted = image_shifted[..., None]
         shifted_masked_kspace = shifted_masked_kspace[..., None]
         mask_batch.append(shifted_mask)
         kspace_batch.append(shifted_masked_kspace)
         img_batch.append(image_shifted)
     kspace_batch = np.array(kspace_batch)
     mask_batch = np.array(mask_batch)
     img_batch = np.array(img_batch)
     if self.inner_slices is not None:
         n_slices = len(kspaces)
         slice_start = n_slices // 2 - self.inner_slices // 2
         kspace_batch = kspace_batch[slice_start:slice_start + self.inner_slices]
         img_batch = img_batch[slice_start:slice_start + self.inner_slices]
         mask_batch = mask_batch[slice_start:slice_start + self.inner_slices]
     return ([kspace_batch, mask_batch], img_batch)
Пример #5
0
 def get_item_train(self, idx):
     filename, position = self.idx_to_filename_and_position[idx]
     images, kspaces = from_train_file_to_image_and_kspace(filename)
     kspace = kspaces[position]
     k_shape = kspace.shape
     mask = gen_mask(kspace, accel_factor=self.af)
     fourier_mask = np.repeat(mask.astype(np.float), k_shape[0], axis=0)
     masked_kspace = kspace * fourier_mask
     image = images[position]
     kspace_batch = masked_kspace[None, ..., None].astype('complex64')
     mask_batch = fourier_mask[None, ...]
     img_batch = image[None, ..., None].astype('float32')
     return ([kspace_batch, mask_batch], img_batch)
Пример #6
0
 def get_item_train(self, idx):
     images, kspaces = self.data[idx]
     images = images[..., None]
     kspaces = kspaces[..., None]
     k_shape = kspaces[0].shape
     mask = gen_mask(kspaces[0, ..., 0], accel_factor=self.af)
     fourier_mask = np.repeat(mask.astype(np.float), k_shape[0], axis=0)
     mask_batch = np.repeat(fourier_mask[None, ...], len(kspaces), axis=0)[..., None]
     kspaces *= mask_batch
     mask_batch = mask_batch[..., 0]
     if self.rand:
         i_slice = random.randint(0, self.inner_slices)
         kspaces = kspaces[i_slice:i_slice+1]
         images = images[i_slice:i_slice+1]
         mask_batch = mask_batch[i_slice:i_slice+1]
     return ([kspaces, mask_batch], images)
Пример #7
0
 def get_item_train(self, idx):
     filename, position = self.idx_to_filename_and_position[idx]
     kspaces = from_file_to_kspace(filename)
     kspace = kspaces[position]
     k_shape = kspace.shape
     mask = gen_mask(kspace, accel_factor=self.af)
     fourier_mask = np.repeat(mask.astype(np.float), k_shape[0], axis=0)
     masked_kspace = kspace * fourier_mask
     masked_kspace *= np.sqrt(np.prod(k_shape))
     shifted_masked_kspace = np.fft.ifftshift(masked_kspace)
     shifted_mask = np.fft.ifftshift(fourier_mask)[None, ...]
     image = np.abs(ifft(kspace))
     image_shifted = np.fft.fftshift(image)
     image_shifted = image_shifted[None, ..., None]
     shifted_masked_kspace = shifted_masked_kspace[None, ..., None]
     return ([shifted_masked_kspace, shifted_mask], image_shifted)
Пример #8
0
 def get_item_train(self, filename):
     images, kspaces = super(MaskedUntouched2DSequence, self).get_item_train(filename)
     k_shape = kspaces[0].shape
     mask = gen_mask(kspaces[0, ..., 0], accel_factor=self.af)
     fourier_mask = np.repeat(mask.astype(np.float), k_shape[0], axis=0)
     mask_batch = np.repeat(fourier_mask[None, ...], len(kspaces), axis=0)[..., None]
     kspaces *= mask_batch
     mask_batch = mask_batch[..., 0]
     if self.inner_slices is not None:
         n_slices = len(kspaces)
         slice_start = n_slices // 2 - self.inner_slices // 2
         if self.rand:
             i_slice = random.randint(slice_start, slice_start + self.inner_slices)
             selected_slices = slice(i_slice, i_slice + 1)
         else:
             selected_slices = slice(slice_start, slice_start + self.inner_slices)
         kspaces = kspaces[selected_slices]
         images = images[selected_slices]
         mask_batch = mask_batch[selected_slices]
     return ([kspaces, mask_batch], images)