示例#1
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)
                    x_final, transform = sparse_rec_fista(
                        gradient_op=gradient_op,
                        linear_op=linear_op,
                        mu=0,
                        lambda_init=1.0,
                        max_nb_of_iter=self.nb_iter,
                        atol=1e-4,
                        verbose=0,
                        get_cost=False)

                    mismatch = (1. - numpy.mean(
                        numpy.isclose(x_final, fourier.adj_op(data),
                                      rtol=1e-3)))
                    print("      mismatch = ", mismatch)
示例#2
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)
                    x_final, transform = sparse_rec_condatvu(
                        gradient_op=gradient_op,
                        linear_op=linear_op,
                        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
示例#3
0
 def test_sampling_converters(self):
     """Test the adjoint operator for the 2D non-Cartesian Fourier transform
     """
     for i in range(self.max_iter):
         print("Process test convert mask to samples test '{0}'...", i)
         Nx = numpy.random.randint(8, 512)
         Ny = numpy.random.randint(8, 512)
         mask = numpy.random.randint(2, size=(Nx, Ny))
         samples = convert_mask_to_locations(mask)
         recovered_mask = convert_locations_to_mask(samples, (Nx, Ny))
         mismatch = (1. - numpy.mean(numpy.allclose(mask, recovered_mask)))
         print("      mismatch = ", mismatch)
     print(" Test convert mask to samples and it's adjoint passes")
示例#4
0
 def test_FFT2(self):
     """Test the adjoint operator for the 2D non-Cartesian Fourier transform
     """
     for i in range(self.max_iter):
         _mask = numpy.random.randint(2, size=(self.N, self.N))
         _samples = convert_mask_to_locations(_mask)
         print("Process FFT2 test '{0}'...", i)
         fourier_op_dir = FFT2(samples=_samples, shape=(self.N, self.N))
         fourier_op_adj = FFT2(samples=_samples, shape=(self.N, self.N))
         Img = numpy.random.randn(self.N, self.N)
         f = numpy.random.randn(self.N, self.N)
         f_p = fourier_op_dir.op(Img) / (self.N**2)
         I_p = fourier_op_adj.adj_op(f)
         x_d = numpy.dot(Img.flatten(), numpy.conj(I_p).flatten())
         x_ad = numpy.dot(f_p.flatten(), numpy.conj(f).flatten())
         mismatch = (1. - numpy.mean(numpy.isclose(x_d, x_ad, rtol=1e-3)))
         print("      mismatch = ", mismatch)
     print(" FFT2 adjoint test passes")
示例#5
0
from pysap.plugins.mri.reconstruct_3D.fourier import NUFFT, NFFT3, FFT3
from pysap.plugins.mri.reconstruct.fourier import NFFT2, FFT2

import numpy as np
from pysap.plugins.mri.reconstruct_3D.utils import convert_mask_to_locations_3D
from pysap.plugins.mri.reconstruct.utils import convert_mask_to_locations
from modopt.math.metrics import mse
import matplotlib.pyplot as plt
from pysap.plugins.mri.parallel_mri.extract_sensitivity_maps import gridding_nd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm

# Sampling pattern (here, random)
_mask = np.ones(np.random.randint(2, size=(512, 512)).shape)
_samples = convert_mask_to_locations(_mask)
_samples_shift = convert_mask_to_locations(np.fft.fftshift(_mask))

# Load images
images = np.load('/volatile/bsarthou/datas/NUFFT/mri_img_2D.npy')
print(images.shape)
# In[3]:

fourier_op_dir_nufft = NUFFT(samples=_samples,
                             platform='cpu',
                             shape=(512, 512),
                             Kd=512,
                             Jd=3)
fourier_op_dir_nfft = NFFT2(samples=_samples, shape=(512, 512))

fourier_op_dir_fft = FFT2(samples=_samples_shift, shape=(512, 512))
示例#6
0
# 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 = prod_over_maps(Smaps, SOS)
kspace_data = function_over_maps(pfft.fft2, Sl)
mask = pysap.Image(data=mask)
kspace_data = prod_over_maps(kspace_data, mask.data)
mask.show()

# Get the locations of the kspace samples
kspace_loc = convert_mask_to_locations(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 = 1

linear_op = Wavelet2(wavelet_name="UndecimatedBiOrthogonalTransform",
                     nb_scale=4)
prox_op = Threshold(None)
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.

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

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

# Zero order solution
image_rec0 = pysap.Image(data=pfft.ifft2(kspace_data), 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.

# Start the FISTA reconstruction
max_iter = 20