Example #1
0
    ifft = lambda x0: np.fft.fftshift(np.fft.ifft2(
        np.fft.ifftshift(x0, axes=(0, 1)), axes=(0, 1)),
                                      axes=(0, 1))
    sos = lambda x0: np.sqrt(np.sum(np.abs(x0)**2, axis=-1))

    # Radially sampled Shepp-Logan
    N, spokes, nc = 288, 72, 8
    kx, ky = radial(N, spokes)
    kx = np.reshape(kx, (N, spokes), 'F').flatten()
    ky = np.reshape(ky, (N, spokes), 'F').flatten()
    k = kspace_shepp_logan(kx, ky, ncoil=nc)
    k = whiten(k)  # whitening seems to help conditioning of Gx, Gy

    # Get the GRAPPA operators
    t0 = time()
    Gx, Gy = radialgrappaop(kx, ky, k, nspokes=spokes)
    print('Gx, Gy computed in %g seconds' % (time() - t0))

    # Do forward GROG (with oversampling)
    t0 = time()
    res_cart = grog(kx, ky, k, 2 * N, 2 * N, Gx, Gy)
    print('Gridded in %g seconds' % (time() - t0))

    # Now back to radial (inverse GROG)
    res_radial = grog(kx,
                      ky,
                      np.reshape(res_cart, (-1, nc), order='F'),
                      2 * N,
                      2 * N,
                      Gx,
                      Gy,
Example #2
0
    # Radially sampled Shepp-Logan
    N, spokes, nc = 288, 72, 8
    kx, ky = radial(N, spokes)
    kx = np.reshape(kx, (N, spokes), 'F').flatten()
    ky = np.reshape(ky, (N, spokes), 'F').flatten()
    k = kspace_shepp_logan(kx, ky, ncoil=nc)
    k = whiten(k)  # whitening seems to help conditioning of Gx, Gy

    # Put in correct shape for radialgrappaop
    k = np.reshape(k, (N, spokes, nc))
    kx = np.reshape(kx, (N, spokes))
    ky = np.reshape(ky, (N, spokes))

    # Get the GRAPPA operators!
    t0 = time()
    Gx, Gy = radialgrappaop(kx, ky, k)
    print('Gx, Gy computed in %g seconds' % (time() - t0))

    # Put in correct order for GROG
    kx = kx.flatten()
    ky = ky.flatten()
    k = np.reshape(k, (-1, nc))

    # Do GROG without primefac
    t0 = time()
    res = grog(kx, ky, k, N, N, Gx, Gy, use_primefac=False)
    print('Gridded in %g seconds' % (time() - t0))

    # Do GROG with primefac
    t0 = time()
    res_prime = grog(kx, ky, k, N, N, Gx, Gy, use_primefac=True)
Example #3
0
from phantominator import kspace_shepp_logan
from phantominator.traj import radial

if __name__ == '__main__':

    # Example usage (requires pygrappa package to be installed!)
    sx, spokes, ncoil = 288, 72, 8
    kx, ky = radial(sx, spokes)
    kx = np.reshape(kx, (sx, spokes), 'F').flatten()
    ky = np.reshape(ky, (sx, spokes), 'F').flatten()
    k = kspace_shepp_logan(kx, ky, ncoil=ncoil)
    k = whiten(k)

    # Grid via GROG and check out the results:
    Gx, Gy = radialgrappaop(
        np.reshape(kx, (sx, spokes)),
        np.reshape(ky, (sx, spokes)),
        np.reshape(k, (sx, spokes, ncoil)))
    coil_ims = np.abs(np.fft.fftshift(np.fft.ifft2(np.fft.ifftshift(
        grog(kx, ky, k, sx, sx, Gx, Gy),
        axes=(0, 1)), axes=(0, 1)), axes=(0, 1)))

    # Some code to look at the animation
    fig = plt.figure()
    ax = plt.imshow(coil_ims[..., 0], cmap='gray')

    def init():
        '''Initialize ax data.'''
        ax.set_array(coil_ims[..., 0])
        return(ax,)

    def animate(frame):