Пример #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(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 = WaveletN(wavelet_name=name, nb_scale=4)
                    gradient_op = GradAnalysis2(data=data,
                                                fourier_op=fourier_op)
                    prox_dual_op = Threshold(0)
                    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,
                        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)
                    fourier_0 = FFT2(samples=convert_mask_to_locations(
                        fftshift(self.mask)),
                                     shape=image.shape)
                    data_0 = fourier_0.op(numpy.fft.fftshift(image.data))

                    self.assertTrue(
                        numpy.allclose(x_final.any(),
                                       numpy.fft.ifftshift(
                                           fourier_0.adj_op(data_0)).any(),
                                       rtol=1e-10))
                    mean_square_error = numpy.mean(
                        numpy.abs(
                            x_final -
                            numpy.fft.ifftshift(fourier_0.adj_op(data_0)))**2)
                    print("      Mean Square Error = ", mean_square_error)
                    return
Пример #2
0
    wavelet_name="BsplineWaveletTransformATrousAlgorithm",
    samples=kspace_loc,
    nb_scales=4,
    non_cartesian=True,
    uniform_data_shape=image.shape,
    gradient_space="analysis")

# Start the CONDAT-VU reconstruction
max_iter = 20
x_final, transform, costs, metrics = sparse_rec_condatvu(
    gradient_op,
    linear_op,
    prox_op,
    cost_op,
    std_est=None,
    std_est_method="dual",
    std_thr=2.,
    mu=1e-9,
    tau=None,
    sigma=None,
    relaxation_factor=1.0,
    nb_of_reweights=2,
    max_nb_of_iter=max_iter,
    add_positivity=False,
    atol=1e-4,
    verbose=1)
image_rec = pysap.Image(data=np.abs(x_final))
image_rec.show()
cost_rec = pysap.Image(data=costs)
cost_rec.show()
Пример #3
0
#
# We now want to refine the zero order solution using a Condat-Vu
# optimization.
# We can't use a FISTA optimisation, which is adapted to solve the synthesis
# formulation of a Lasso.
# But here, we need to use the analysis formulation since the learnt
# dictionary is not a basis anymore. It is redundant.

x, y, costs, metrics = sparse_rec_condatvu(gradient_op=gradient_op,
                                           linear_op=linear_op,
                                           prox_dual_op=prox_dual_op,
                                           cost_op=cost_op,
                                           std_est=None,
                                           std_est_method=None,
                                           std_thr=2.,
                                           mu=0.1,
                                           tau=None,
                                           sigma=None,
                                           relaxation_factor=1.0,
                                           nb_of_reweights=0,
                                           max_nb_of_iter=2,
                                           add_positivity=False,
                                           atol=1e-4,
                                           verbose=1)

#############################################################################
# Visualizing the results
# -----------------------

# Solution in the image domain
image_rec = pysap.Image(data=min_max_normalize(np.abs(x)))
image_rec.show()