Exemple #1
0
    def test_nufft_adjoint(self):

        # Check deltas
        oshape = [3]
        input = np.array([1.0, 1.0, 1.0], dtype=np.complex) / 3**0.5
        coord = np.array([[-1], [0], [1]], np.float)

        npt.assert_allclose(fourier.nufft_adjoint(input, coord, oshape),
                            np.array([0, 1, 0]),
                            atol=0.01,
                            rtol=0.01)

        oshape = [4]
        input = np.array([1.0, 1.0, 1.0, 1.0], dtype=np.complex) / 4**0.5
        coord = np.array([[-2], [-1], [0], [1]], np.float)

        npt.assert_allclose(fourier.nufft_adjoint(input, coord, oshape),
                            np.array([0, 0, 1, 0], np.complex),
                            atol=0.01,
                            rtol=0.01)

        oshape = [5]
        input = np.ones(5, dtype=np.complex) / 5**0.5
        coord = np.array([[-2], [-1], [0], [1], [2]], np.float)

        npt.assert_allclose(fourier.nufft_adjoint(input, coord, oshape),
                            np.array([0, 0, 1, 0, 0], np.complex),
                            atol=0.01,
                            rtol=0.01)

        # Check shifted delta
        oshape = [3]
        w = np.exp(-1j * 2.0 * np.pi / 3.0)
        input = np.array([w.conjugate(), 1.0, w]) / 3**0.5
        coord = np.array([[-1], [0], [1]], np.float)

        npt.assert_allclose(fourier.nufft_adjoint(input, coord, oshape),
                            np.array([0, 0, 1], np.complex),
                            atol=0.01,
                            rtol=0.01)

        oshape = [4]
        w = np.exp(-1j * 2.0 * np.pi / 4.0)
        input = np.array([w.conjugate()**2, w.conjugate(), 1.0, w]) / 4**0.5
        coord = np.array([[-2], [-1], [0], [1]], np.float)

        npt.assert_allclose(fourier.nufft_adjoint(input, coord, oshape),
                            np.array([0, 0, 0, 1], np.complex),
                            atol=0.01,
                            rtol=0.01)
Exemple #2
0
 def _apply(self, input):
     return fourier.nufft_adjoint(input,
                                  self.coord,
                                  self.oshape,
                                  oversamp=self.oversamp,
                                  width=self.width,
                                  n=self.n)
Exemple #3
0
 def _apply(self, input):
     device = backend.get_device(input)
     with device:
         coord = backend.to_device(self.coord, device)
         return fourier.nufft_adjoint(
             input, coord, self.oshape,
             oversamp=self.oversamp, width=self.width)
Exemple #4
0
    def test_nufft_adjoint_nd(self):

        oshape = [3, 1]

        input = np.array([1.0, 1.0, 1.0], dtype=np.complex) / 3**0.5
        coord = np.array([[-1, 0], [0, 0], [1, 0]], np.float)

        npt.assert_allclose(fourier.nufft_adjoint(input, coord, oshape),
                            np.array([[0], [1], [0]], np.complex),
                            atol=0.01,
                            rtol=0.01)
Exemple #5
0
    def test_nufft_normal(self):

        # Check delta
        oshape = [3]
        input = np.array([0.0, 1.0, 0.0], dtype=np.complex)
        coord = np.array([[-1], [0], [1]], np.float)

        npt.assert_allclose(fourier.nufft_adjoint(fourier.nufft(input, coord),
                                                  coord, oshape),
                            np.array([0, 1, 0]),
                            atol=0.01,
                            rtol=0.01)

        # Check delta scale
        oshape = [3]
        input = np.array([0.0, 1.0, 0.0], dtype=np.complex)
        coord = np.array([[-1], [-0.5], [0], [0.5], [1]], np.float)

        npt.assert_allclose(fourier.nufft_adjoint(fourier.nufft(input,
                                                                coord), coord,
                                                  oshape)[len(input) // 2],
                            5 / 3,
                            atol=0.01,
                            rtol=0.01)
Exemple #6
0
    elif trajectory == 'spiral':
        traj = Spiral(FOV=FOV,
                      res=res,
                      oversampling=2,
                      lines_per_shot=2,
                      interleaves=10)
    # traj.plot_trajectory()

    # Non-cartesian kspace
    K = TrajToImage(traj.points, 1000.0 * traj.times, Mxy, r, 50.0)

    # Non-uniform fft
    x0 = traj.points[0].flatten().reshape((-1, 1))
    x1 = traj.points[1].flatten().reshape((-1, 1))
    x0 *= res[0] // 2 / x0.max()
    x1 *= res[1] // 2 / x1.max()
    dcf = (x0**2 + x1**2)**0.5  # density compensation function
    kxky = np.concatenate((x0, x1), axis=1)  # flattened kspace coordinates
    y = K.flatten().reshape((-1, 1))  # flattened kspace measures
    image = nufft_adjoint(y * dcf, kxky, res)  # inverse nufft

    # Show results
    fig, axs = plt.subplots(2, 3, figsize=(10, 10))
    axs[0, 0].imshow(np.abs(K_c[::2, :]))
    axs[0, 1].imshow(np.abs(ktoi(K_c[::2, :])))
    axs[0, 2].imshow(np.angle(ktoi(K_c[::2, :])))
    axs[1, 0].imshow(np.abs(itok(image)))
    axs[1, 1].imshow(np.abs(image))
    axs[1, 2].imshow(np.angle(image))
    plt.show()