Exemplo n.º 1
0
 def test_columnFFT_forward(self):
     """Test the forward operator of ColumnFFT."""
     column_indexes = np.arange(64)
     mask = np.ones(self.shape)
     for nc in self.n_coils:
         fourier_op = FFT(mask=mask, shape=self.shape, n_coils=nc)
         column_fft = ColumnFFT(shape=self.shape, line_index=0, n_coils=nc)
         data = np.squeeze(np.random.rand(fourier_op.n_coils, *self.shape))
         k_data = fourier_op.op(data)
         for col in column_indexes:
             column_fft.mask = col
             np.testing.assert_allclose(column_fft.op(data),
                                        k_data[..., column_fft.mask])
     print("Test forward operator of columnFFT")
Exemplo n.º 2
0
 def test_self_calibrating_reconstruction(self):
     """ Test all the registered transformations.
     """
     self.num_channels = 2
     print("Process test for SelfCalibratingReconstructor ::")
     for i in range(len(self.test_cases)):
         print("Test Case " + str(i) + " " + str(self.test_cases[i]))
         image, nb_scale, optimizer, recon_type, name = self.test_cases[i]
         image_multichannel = np.repeat(image.data[np.newaxis],
                                        self.num_channels,
                                        axis=0)
         if optimizer == 'condatvu':
             formulation = "analysis"
         else:
             formulation = "synthesis"
         if recon_type == 'cartesian':
             fourier = FFT(samples=convert_mask_to_locations(self.mask),
                           shape=image.shape,
                           n_coils=self.num_channels)
         else:
             fourier = NonCartesianFFT(samples=convert_mask_to_locations(
                 self.mask),
                                       shape=image.shape,
                                       n_coils=self.num_channels)
         kspace_data = fourier.op(image_multichannel)
         linear_op, regularizer_op = \
             self.get_linear_n_regularization_operator(
                 wavelet_name=name,
                 dimension=len(fourier.shape),
                 nb_scale=2,
                 n_coils=self.num_channels,
                 gradient_formulation=formulation,
             )
         # For self calibrating reconstruction the n_coils
         # for wavelet operation is 1
         linear_op.n_coils = 1
         reconstructor = SelfCalibrationReconstructor(
             fourier_op=fourier,
             linear_op=linear_op,
             regularizer_op=regularizer_op,
             gradient_formulation=formulation,
             verbose=0,
         )
         x_final, costs, _ = reconstructor.reconstruct(
             kspace_data=kspace_data,
             optimization_alg=optimizer,
             num_iterations=self.num_iter,
         )
         fourier_0 = FFT(
             samples=convert_mask_to_locations(self.mask),
             shape=image.shape,
             n_coils=self.num_channels,
         )
         recon = fourier_0.adj_op(fourier_0.op(image_multichannel))
         np.testing.assert_allclose(np.abs(x_final),
                                    np.sqrt(np.sum(np.abs(recon)**2,
                                                   axis=0)),
                                    rtol=1e-3)
Exemplo n.º 3
0
 def test_sparse_calibrationless_reconstruction(self):
     """ Test all the registered transformations.
     """
     self.num_channels = 2
     print("Process test for SparseCalibrationlessReconstructor ::")
     for i in range(len(self.test_cases)):
         print("Test Case " + str(i) + " " + str(self.test_cases[i]))
         image, nb_scale, optimizer, recon_type, name = self.test_cases[i]
         image_multichannel = np.repeat(image.data[np.newaxis],
                                        self.num_channels,
                                        axis=0)
         if optimizer == 'condatvu':
             formulation = "analysis"
         else:
             formulation = "synthesis"
         if recon_type == 'cartesian':
             fourier = FFT(samples=convert_mask_to_locations(self.mask),
                           shape=image.shape,
                           n_coils=self.num_channels)
         else:
             fourier = NonCartesianFFT(samples=convert_mask_to_locations(
                 self.mask),
                                       shape=image.shape,
                                       n_coils=self.num_channels)
         kspace_data = fourier.op(image_multichannel)
         linear_op, regularizer_op = \
             self.get_linear_n_regularization_operator(
                 wavelet_name=name,
                 dimension=len(fourier.shape),
                 nb_scale=2,
                 n_coils=2,
                 n_jobs=2,
                 gradient_formulation=formulation,
             )
         reconstructor = CalibrationlessReconstructor(
             fourier_op=fourier,
             linear_op=linear_op,
             regularizer_op=regularizer_op,
             gradient_formulation=formulation,
             verbose=1,
         )
         x_final, costs, _ = reconstructor.reconstruct(
             kspace_data=kspace_data,
             optimization_alg=optimizer,
             num_iterations=self.num_iter,
         )
         fourier_0 = FFT(
             samples=convert_mask_to_locations(self.mask),
             shape=image.shape,
             n_coils=self.num_channels,
         )
         data_0 = fourier_0.op(image_multichannel)
         # mu is 0 for above single channel reconstruction and
         # hence we expect the result to be the inverse fourier transform
         np.testing.assert_allclose(x_final, fourier_0.adj_op(data_0))
Exemplo n.º 4
0
 def test_columnFFT_adjoint(self):
     """Test the adjoint operator of column FFT. """
     column_indexes = np.arange(0, 64)
     mask = np.ones(self.shape)
     for nc in self.n_coils:
         fft2d = FFT(mask=mask, shape=self.shape, n_coils=nc)
         column_fft = ColumnFFT(shape=self.shape, line_index=0, n_coils=nc)
         k_data = np.squeeze(
             np.random.rand(fft2d.n_coils, *self.shape) +
             1j * np.random.rand(fft2d.n_coils, *self.shape))
         for col in column_indexes:
             column_fft.mask = col
             mask = np.zeros(self.shape)
             mask[:, column_fft.mask] = 1
             fft2d.mask = mask
             print(np.nonzero(fft2d.mask[0, :]))
             print(column_fft.mask)
             print(column_fft.adj_op(k_data[..., column_fft._mask])[0, :5])
             print(fft2d.adj_op(k_data)[0, :5])
             np.testing.assert_allclose(
                 column_fft.adj_op(k_data[..., column_fft._mask]),
                 fft2d.adj_op(k_data))
     print("Test adjoint operator of columnFFT")
Exemplo n.º 5
0
 def test_stack3d_self_calibration_recon(self):
     # This test carries out a self calibration recon using Stack3D
     self.num_channels = 2
     self.z_size = 10
     for i in range(len(self.test_cases)):
         image, nb_scale, optimizer, recon_type, name = self.test_cases[i]
         if recon_type == 'cartesian' or name == 24:
             continue
         # Make a dummy 3D image from 2D
         image = np.moveaxis(
             np.repeat(image.data[np.newaxis], self.z_size, axis=0), 0, 2)
         # Make dummy multichannel image
         image = np.repeat(image[np.newaxis], self.num_channels, axis=0)
         sampling_z = np.random.randint(2, size=image.shape[3])
         sampling_z[self.z_size // 2 - 3:self.z_size // 2 + 3] = 1
         Nz = sampling_z.sum()
         mask = convert_mask_to_locations(self.mask)
         z_locations = np.repeat(convert_mask_to_locations(sampling_z),
                                 mask.shape[0])
         z_locations = z_locations[:, np.newaxis]
         kspace_loc = np.hstack([np.tile(mask, (Nz, 1)), z_locations])
         fourier = Stacked3DNFFT(kspace_loc=kspace_loc,
                                 shape=image.shape[1:],
                                 implementation='cpu',
                                 n_coils=self.num_channels)
         kspace_obs = fourier.op(image)
         if optimizer == 'condatvu':
             formulation = "analysis"
         else:
             formulation = "synthesis"
         linear_op, regularizer_op = \
             self.get_linear_n_regularization_operator(
                 wavelet_name=name,
                 dimension=len(fourier.shape),
                 nb_scale=2,
                 n_coils=2,
                 n_jobs=2,
                 gradient_formulation=formulation,
             )
         # For self calibrating reconstruction the n_coils
         # for wavelet operation is 1
         linear_op.n_coils = 1
         reconstructor = SelfCalibrationReconstructor(
             fourier_op=fourier,
             linear_op=linear_op,
             regularizer_op=regularizer_op,
             gradient_formulation=formulation,
             num_check_lips=0,
             smaps_extraction_mode='Stack',
             verbose=1,
         )
         x_final, _, _, = reconstructor.reconstruct(
             kspace_data=kspace_obs,
             optimization_alg=optimizer,
             num_iterations=5,
         )
         fourier_0 = FFT(
             samples=kspace_loc,
             shape=image.shape[1:],
             n_coils=self.num_channels,
         )
         recon = fourier_0.adj_op(fourier_0.op(image))
         np.testing.assert_allclose(
             np.abs(x_final), np.sqrt(np.sum(np.abs(recon)**2, axis=0)),
             0.1)
Exemplo n.º 6
0
    def test_online_accumulating_calibrationless(self):
        self.num_channels = 2
        for i in range(len(self.test_cases)):
            image, nb_scale, optimizer, recon_type, name = self.test_cases[i]
            if recon_type != 'cartesian':
                continue
            if optimizer == 'condatvu':
                formulation = "analysis"
            else:
                formulation = "synthesis"
            image_multichannel = np.repeat(image.data[np.newaxis],
                                           self.num_channels,
                                           axis=0)

            fourier = FFT(samples=convert_mask_to_locations(self.mask),
                          shape=image.shape,
                          n_coils=self.num_channels)
            kspace_data = fourier.op(image_multichannel)

            linear_op, _ = \
                self.get_linear_n_regularization_operator(
                    wavelet_name=name,
                    dimension=len(fourier.shape),
                    nb_scale=2,
                    n_coils=2,
                    n_jobs=2,
                    image_shape=image.shape,
                )
            regularizer_op_gl = GroupLASSO(weights=0)
            linear_op.op(image_multichannel)
            regularizer_op_owl = OWL(
                alpha=0,
                beta=0,
                mode='band_based',
                n_coils=self.num_channels,
                bands_shape=linear_op.coeffs_shape,
            )
            for regularizer_op in [regularizer_op_gl, regularizer_op_owl]:
                print(image, nb_scale, optimizer, recon_type, name,
                      regularizer_op)
                kspace_gen = KspaceGeneratorBase(full_kspace=kspace_data,
                                                 mask=fourier.mask,
                                                 max_iter=10)
                reconstructor = CalibrationlessReconstructor(
                    fourier_op=fourier,
                    linear_op=linear_op,
                    regularizer_op=regularizer_op,
                    gradient_formulation=formulation,
                    num_check_lips=0,
                    verbose=1,
                )
                x_final, costs, _ = reconstructor.reconstruct(
                    kspace_data=kspace_gen,
                    optimization_alg=optimizer,
                )
                fourier_0 = FFT(
                    samples=convert_mask_to_locations(self.mask),
                    shape=image.shape,
                    n_coils=self.num_channels,
                )
                data_0 = fourier_0.op(image_multichannel)
                # mu is 0 for above single channel reconstruction and
                # hence we expect the result to be the inverse fourier
                # transform
                np.testing.assert_allclose(x_final, fourier_0.adj_op(data_0),
                                           0.01)