Exemple #1
0
 def test_reconstruction_condat_vu_fft2(self):
     """ Test all the registered transformations.
     """
     print("Process test FFT2 Condat Vu algorithm::")
     for image in self.images:
         fourier = FFT2(samples=convert_mask_to_locations(
             fftshift(self.mask)),
                        shape=image.shape)
         data = fourier.op(image.data)
         fourier_op = FFT2(samples=convert_mask_to_locations(
             fftshift(self.mask)),
                           shape=image.shape)
         print("Process test with image '{0}'...".format(
             image.metadata["path"]))
         for nb_scale in self.nb_scales:
             print("- Number of scales: {0}".format(nb_scale))
             for name in self.names:
                 print("    Transform: {0}".format(name))
                 linear_op = Wavelet2(wavelet_name=name, nb_scale=4)
                 gradient_op = GradAnalysis2(data=data,
                                             fourier_op=fourier_op)
                 prox_dual_op = Threshold(None)
                 x_final, transform, _, _ = sparse_rec_condatvu(
                     gradient_op=gradient_op,
                     linear_op=linear_op,
                     prox_dual_op=prox_dual_op,
                     cost_op=None,
                     std_est=0.0,
                     std_est_method="dual",
                     std_thr=0,
                     mu=0,
                     tau=None,
                     sigma=None,
                     relaxation_factor=1.0,
                     nb_of_reweights=0,
                     max_nb_of_iter=self.nb_iter,
                     add_positivity=False,
                     atol=1e-4,
                     verbose=0)
                 mismatch = (1. - numpy.mean(
                     numpy.isclose(x_final, fourier.adj_op(data),
                                   rtol=1e-3)))
                 print("      mismatch = ", mismatch)
                 return
Exemple #2
0
 def test_reconstruction_fista_fft2(self):
     """ Test all the registered transformations.
     """
     print("Process test FFT2 FISTA::")
     for image in self.images:
         fourier = FFT2(samples=convert_mask_to_locations(
             fftshift(self.mask)),
                        shape=image.shape)
         data = fourier.op(image.data)
         fourier_op = FFT2(convert_mask_to_locations(fftshift(self.mask)),
                           shape=image.shape)
         print("Process test with image '{0}'...".format(
             image.metadata["path"]))
         for nb_scale in self.nb_scales:
             print("- Number of scales: {0}".format(nb_scale))
             for name in self.names:
                 print("    Transform: {0}".format(name))
                 linear_op = Wavelet2(wavelet_name=name, nb_scale=4)
                 gradient_op = GradSynthesis2(data=data,
                                              fourier_op=fourier_op,
                                              linear_op=linear_op)
                 prox_op = Threshold(None)
                 x_final, transform, _, _ = sparse_rec_fista(
                     gradient_op=gradient_op,
                     linear_op=linear_op,
                     prox_op=prox_op,
                     cost_op=None,
                     mu=0,
                     lambda_init=1.0,
                     max_nb_of_iter=self.nb_iter,
                     atol=1e-4,
                     verbose=0)
                 mismatch = (1. - numpy.mean(
                     numpy.isclose(x_final, fourier.adj_op(data),
                                   rtol=1e-3)))
                 print("      mismatch = ", mismatch)
#############################################################################
# Generate the kspace
# -------------------
#
# From the 2D brain slice and the acquistion mask, we generate the acquisition
# measurments, the observed kspace.
# We then reconstruct the zero order solution.

# Generate the subsampled kspace
Sl = np.asarray([Smaps[l] * SOS for l in range(Smaps.shape[0])])
kspace_data = np.asarray([mask * pfft.fft2(Sl[l]) for l in range(Sl.shape[0])])
mask = pysap.Image(data=pfft.fftshift(mask))
mask.show()

# Get the locations of the kspace samples
kspace_loc = convert_mask_to_locations(pfft.fftshift(mask.data))

#############################################################################
# FISTA optimization
# ------------------
#
# We now want to refine the zero order solution using a FISTA optimization.
# Here no cost function is set, and the optimization will reach the
# maximum number of iterations. Fill free to play with this parameter.

# Start the FISTA reconstruction
max_iter = 10

linear_op = Wavelet2(wavelet_name="UndecimatedBiOrthogonalTransform",
                     nb_scale=4)
prox_op = Threshold(None)
image = get_sample_data("mri-slice-nifti")
image.data += np.random.randn(*image.shape) * 20.
mask = get_sample_data("mri-mask")
image.show()
mask.show()

#############################################################################
# Generate the kspace
# -------------------
#
# From the 2D brain slice and the acquistion mask, we generate the acquisition
# measurments, the observed kspace.
# We then reconstruct the zero order solution.

# Get the locations of the kspace samples and the associated observations
kspace_loc = convert_mask_to_locations(mask.data)
fourier_op = NFFT2(samples=kspace_loc, shape=image.shape)
kspace_obs = fourier_op.op(image.data)

# Zero order solution
image_rec0 = pysap.Image(data=fourier_op.adj_op(kspace_obs),
                         metadata=image.metadata)
image_rec0.show()

#############################################################################
# FISTA optimization
# ------------------
#
# We now want to refine the zero order solution using a FISTA optimization.
# Here no cost function is set, and the optimization will reach the
# maximum number of iterations. Fill free to play with this parameter.
Exemple #5
0
# Verbose parameters, activated if >1
verbose_reconstruction = 0
verbose_gridsearch = 11

# Data loading
ref = get_sample_data("mri-slice-nifti")
ref.data = ref.data / np.linalg.norm(ref.data)
mask = get_sample_data("mri-mask")

# Generate the subsampled kspace
kspace_mask = pfft.ifftshift(mask.data)
kspace = pfft.fft2(ref.data) * kspace_mask

# Get the locations of the kspace samples
loc = convert_mask_to_locations(kspace_mask)

# Create noise
noise = sigma * (randn(*kspace.shape) + 1.j * randn(*kspace.shape))

# Add noise
kspace = kspace + noise

# Binary mask
binmask = np.ones(ref.shape)


#############################################################################
# Declaration of metrics
# ----------------------
#