Exemplo n.º 1
0
def test():
    # simulated image
    mat_contents = sio.loadmat('data/brain_32ch.mat');
    x            = mat_contents["DATA"] 
    #mask         = mat_contents["mask_randm_x3"].astype(np.float)    
    nx,ny,nc     = x.shape
    #crop k-space
    xcrop        = ut.crop2d( x, 16 )  
    if 0:#do espirit 
        Vim, sim     = espirit_2d(xcrop, x.shape,\
         nsingularv = 150, hkwin_shape = (16,16,16), pad_before_espirit = 0, pad_fact = 2 )
        #coil map
        ut.plotim3(np.absolute(Vim),[4,-1],bar = 1)
        ut.plotim1(np.absolute(sim),bar = 1)
        #create espirit operator
        esp = opts.espirit(Vim)
        esp.save('../save_data/espirit_data_2d.mat')
        #esp.save('/working/larson/UTE_GRE_shuffling_recon/python_test/save_data/espirit_data_2d.mat')        
    else:
        esp = opts.espirit()
        esp.restore('../save_data/espirit_data_2d.mat')
        #esp.restore('/working/larson/UTE_GRE_shuffling_recon/python_test/save_data/espirit_data_2d.mat') 

    #create mask
    mask = ut.mask2d( nx, ny, center_r = 15, undersampling = 0.25 )
    #FTm  = opts.FFT2d_kmask(mask)
    FTm  = opts.FFTW2d_kmask(mask)
    #ut.plotim1(np.absolute(mask))#plot the mask
    Aopt = opts.joint2operators(esp, FTm)
    #create image
    im   = FTm.backward(x)
    #ut.plotim3(np.absolute(im[:,:,:]))
    #wavelet operator
    dwt  = opts.DWT2d(wavelet = 'haar', level=4)
    # undersampling in k-space
    b = FTm.forward(im)
    scaling = ut.optscaling(FTm,b)
    b = b/scaling
    ut.plotim1(np.absolute(Aopt.backward(b))) #undersampled imag

    #do cs mri recon
    Nite = 40 #number of iterations
    step = 0.5 #step size
    tv_r = 0.002 # regularization term for tv term
    rho  = 1.0
    #th   = 1 #threshold
    #xopt = solvers.IST_2(FTm.forward,FTm.backward,b, Nite, step,th) #soft thresholding
    xopt = solvers.ADMM_l2Afxnb_tvx( Aopt.forward, Aopt.backward, b, Nite, step, tv_r, rho)
    #xopt = solvers.ADMM_l2Afxnb_l1x_2( FTm.forward, FTm.backward, b, Nite, step, 100, 1 )

    ut.plotim3(np.absolute(xopt))
Exemplo n.º 2
0
def test():
    # simulated image
    mat_contents = sio.loadmat('data/brain_32ch.mat')
    x = mat_contents["DATA"]
    #mask         = mat_contents["mask_randm_x3"].astype(np.float)
    nx, ny, nc = x.shape
    #crop k-space
    xcrop = ut.crop2d(x, 16)
    if 0:  #do espirit
        Vim, sim     = espirit_2d(xcrop, x.shape,\
         nsingularv = 150, hkwin_shape = (16,16,16), pad_before_espirit = 0, pad_fact = 2 )
        #coil map
        ut.plotim3(np.absolute(Vim), [4, -1], bar=1)
        ut.plotim1(np.absolute(sim), bar=1)
        #create espirit operator
        esp = opts.espirit(Vim)
        esp.save('../save_data/espirit_data_2d.mat')
    else:
        esp = opts.espirit()
        esp.restore('../save_data/espirit_data_2d.mat')
    #create mask
    mask = ut.mask2d(nx, ny, center_r=15, undersampling=0.25)
    FTm = opts.FFT2d_kmask(mask)
    ut.plotim1(np.absolute(mask))  #plot the mask
    Aopt = opts.joint2operators(esp, FTm)
    #create image
    im = FTm.backward(x)
    #ut.plotim3(np.absolute(im[:,:,:]))
    #wavelet operator
    dwt = opts.DWT2d(wavelet='haar', level=4)
    # undersampling in k-space
    b = FTm.forward(im)
    scaling = ut.optscaling(FTm, b)
    b = b / scaling
    ut.plotim1(np.absolute(Aopt.backward(b)))  #undersampled imag
    #do soft thresholding
    Nite = 50  #number of iterations
    step = 1  #step size
    th = 0.1  # theshold level
    #xopt = solvers.IST_2(FTm.forward, FTm.backward, b, Nite, step,th)
    xopt = solvers.FIST_3(Aopt.forward, Aopt.backward, dwt.backward,
                          dwt.forward, b, Nite, step, th)
    ut.plotim3(np.absolute(xopt))
Exemplo n.º 3
0
def test():
    ft = opts.FFT2d()
    mat_contents = sio.loadmat(
        '/working/larson/UTE_GRE_shuffling_recon/20170718_voluteer_ir_fulksp/exp2_ir_fulksp/rawdata.mat'
    )
    x = mat_contents["da"].squeeze(axis=0).squeeze(axis=3)
    mask = mat_contents["mask"].squeeze(axis=0).squeeze(axis=3)
    Vim = mat_contents["calib"][40, ...]
    #ut.plotim3(np.absolute(x[:,:,:,0]))
    im = ft.backward(x)
    ut.plotim3(np.absolute(im[:, :, im.shape[2] // 2, :]))
    #get shape
    nx, ny, nc, nd = x.shape
    #create espirit operator
    esp = opts.espirit(Vim)

    #FTm  = opts.FFTnd_kmask(mask)
    FTm = opts.FFTW2d_kmask(mask, threads=5)
    #ut.plotim1(np.absolute(mask))#plot the mask
    Aopt = opts.joint2operators(esp, FTm)
    #create image
    im = FTm.backward(x)
    #ut.plotim3(np.absolute(im[:,:,:]))
    #wavelet operator
    dwt = opts.DWT2d(wavelet='haar', level=4)
    # undersampling in k-space
    b = FTm.forward(im)
    scaling = ut.optscaling(FTm, b)
    b = b / scaling
    #ut.plotim3(np.absolute(Aopt.backward(b))) #undersampled imag

    #do tv cs mri recon
    #Nite = 20 #number of iterations
    #step = 0.5 #step size
    #tv_r = 0.002 # regularization term for tv term
    #rho  = 1.0
    #xopt = solvers.ADMM_l2Afxnb_tvx( Aopt.forward, Aopt.backward, b, Nite, step, tv_r, rho )

    #do wavelet l1 soft thresholding
    Nite = 50  #number of iterations
    step = 1  #step size
    th = 0.1  # theshold level
    xopt = solvers.FIST_3(Aopt.forward, Aopt.backward, dwt.backward,
                          dwt.forward, b, Nite, step, th)

    ut.plotim3(np.absolute(xopt[:, :, :]))
Exemplo n.º 4
0
def test():
    ft = opts.FFT2d()
    # simulated image
    mat_contents = sio.loadmat('data/brain_32ch.mat');
    x = mat_contents["DATA"]    
    #ut.plotim1(np.absolute(x[:,:,0]))
    im = ft.backward(x[:,:,:])
    ut.plotim3(np.absolute(im[:,:,:]))
    #crop k-space
    xcrop = ut.crop2d( x, 16 )  
    #do espirit2d  
    Vim, sim = espirit_2d(xcrop, x.shape,\
     nsingularv = 150, hkwin_shape = (16,16,16), pad_before_espirit = 0, pad_fact = 2 )
    ut.plotim3(np.absolute(Vim))
    esp = opts.espirit(Vim)
    esp_im = esp.backward(im)
    ut.plotim1(np.absolute(esp_im))
    im_recon = esp.forward(esp_im)
    ut.plotim3(np.absolute(im_recon[:,:,:]))
Exemplo n.º 5
0
def test():
    ft = opts.FFTnd()
    # simulated image
    mat_contents = sio.loadmat(
        '/working/larson/UTE_GRE_shuffling_recon/brain_mt_recon_20160919/brain_3dMRI_32ch.mat'
    )
    x = mat_contents["DATA"]
    #ut.plotim3(np.absolute(x[:,:,:,0]))
    im = ft.backward(x)
    ut.plotim3(np.absolute(im[:, :, im.shape[2] // 2, :]))
    #crop k-space
    xcrop = ut.crop3d(x, 12)
    #do espirit2d
    Vim, sim = espirit_3d(xcrop, x.shape, 150, hkwin_shape = (12,12,12),\
     pad_before_espirit = 0, pad_fact = 2)
    esp = opts.espirit(Vim)
    esp_im = esp.backward(im)
    ut.plotim3(np.absolute(esp_im[:, :, :]))
    im_recon = esp.forward(esp_im)
    ut.plotim3(np.absolute(im_recon[:, :, im.shape[2] // 2, :]))
Exemplo n.º 6
0
def ReconstructADMM_2D(fullysampled_kdata,
                       mask,
                       iterations=10,
                       step=0.05,
                       tv_r=0.005,
                       rho=1.0,
                       is_show=True):
    fullysampled_kdata = fullysampled_kdata[..., np.newaxis]
    FTm = opts.FFTW2d_kmask(mask)

    esp = opts.espirit(sensitivity=np.ones_like(fullysampled_kdata))
    Aopt = opts.joint2operators(esp, FTm)

    im = FTm.backward(fullysampled_kdata)
    dwt = opts.DWT2d(wavelet='haar', level=4)

    # undersampling in k-space
    b = FTm.forward(im)
    scaling = ut.optscaling(FTm, b)
    b = b / scaling

    # do cs mri recon
    Nite = iterations  # number of iterations
    step = step  # step size
    tv_r = tv_r  # regularization term for tv term
    rho = rho
    # th = 1  # threshold

    # xopt = solvers.IST_2(FTm.forward,FTm.backward,b, Nite, step,th) #soft thresholding
    xopt = solvers.ADMM_l2Afxnb_tvx(Aopt.forward,
                                    Aopt.backward,
                                    b,
                                    Nite,
                                    step,
                                    tv_r,
                                    rho,
                                    is_show=is_show)
    # xopt = solvers.ADMM_l2Afxnb_l1x_2( FTm.forward, FTm.backward, b, Nite, step, 100, 1 )

    # ut.plotim3(np.absolute(xopt))
    return xopt
def test1():
    #ft = opts.FFTnd()
    #mat_contents = sio.loadmat(pathdat + 'rawdata2.mat');
    #x = mat_contents["dataall"][...,0,11:13].astype(np.complex64)#.squeeze(axis = 4)
    #Vim = mat_contents["calib"].astype(np.complex64)
    #mask = mat_contents["maskn"][...,0,11:13].astype(np.complex64)#.squeeze(axis = 4)

    mat_contents = h5py.File(pathdat + 'rawdata.mat')

    x = mat_contents['dataall'][:].transpose(
        [5, 4, 3, 2, 1,
         0]).squeeze(axis=4).view(np.complex128).astype(np.complex64)
    Vim = mat_contents["calib"][:].transpose([3, 2, 1, 0]).view(
        np.complex128).astype(np.complex64)
    mask = mat_contents["maskn"][:].transpose([5, 4, 3, 2, 1,
                                               0]).squeeze(axis=4)

    for dd in range(x.shape[-1]):
        esp = opts.espirit(Vim)
        #FTm  = opts.FFTnd_kmask(mask...,dd])
        #FTm = opts.FFTWnd_kmask(mask[...,dd], threads = 15)
        FTm = cuopts.FFTnd_cuda_kmask(mask[..., dd])
        Aopt = opts.joint2operators(esp, FTm)
        #wavelet operator
        dwt = opts.DWTnd(wavelet='db2', level=4, axes=(0, 1, 2))
        # undersampling in k-space
        b = x[..., dd]
        scaling = ut.optscaling(Aopt, b)
        b = b / scaling
        #do wavelet l1 soft thresholding
        xopt = scaling * solvers.FIST_3(Aopt.forward,
                                        Aopt.backward,
                                        dwt.backward,
                                        dwt.forward,
                                        b,
                                        Nite=25,
                                        step=0.5,
                                        th=0.1)
        sio.savemat(pathdat + 'mripy_recon_l1wavelet' + str(dd) + '.mat',
                    {'xopt': xopt})
Exemplo n.º 8
0
def test():
    #path = '/home/pcao/3d_recon/'
    #matfile = 'Phantom_res256_256_20.mat'
    #phantom data
    #path = '/working/larson/UTE_GRE_shuffling_recon/UTEcones_recon/20170301/scan_1_phantom/'
    #matfile = 'Phantom_utecone.mat'
    #lung data
    path = '/working/larson/UTE_GRE_shuffling_recon/UTEcones_recon/20170301/lung_exp4_no_prep/'
    matfile = 'lung_utecone.mat'

    mat_contents = sio.loadmat(path + matfile)

    ktraj = mat_contents["ktraj"]
    dcf = mat_contents["dcf"]
    kdata = mat_contents["kdata"].astype(np.complex64)
    ncoils = kdata.shape[3]

    #bart nufft assumes the im_shape is weighted on ktraj, so I can extract this info here
    im_shape = [
        2 * int(np.max(ktraj[0])), 2 * int(np.max(ktraj[1])),
        2 * int(np.max(ktraj[2]))
    ]
    # remove the weighting of im_shape from ktraj
    ktraj[0, :] = ktraj[0, :] * (1.0 / im_shape[0])
    ktraj[1, :] = ktraj[1, :] * (1.0 / im_shape[1])
    ktraj[2, :] = ktraj[2, :] * (1.0 / im_shape[2])
    #reshape the kdata, flatten the xyz dims
    kdata = kdata.reshape((np.prod(kdata.shape[0:3]), ncoils)).squeeze()
    #call nufft3d here
    nft = cuoptc.NUFFT3d_cuda(im_shape, dcf)
    #nft = optc.NUFFT3d(im_shape, dcf)
    nft.normalize_set_ktraj(ktraj)
    ft = opts.FFTnd()

    im = nft.backward(kdata)

    x = ft.forward(im)
    ut.plotim3(np.absolute(im[:, :, :, 1]), pause_close=5)
    #get shape
    #nx,ny,nz,nc  = x.shape
    #crop k-space
    xcrop = ut.crop3d(x, 12)
    if 0:  #do espirit
        Vim, sim = espirit_3d(xcrop, x.shape, 500, hkwin_shape = (12,12,12),\
         pad_before_espirit = 0, pad_fact = 2, sigv_th = 0.001, nsigv_th = 0.2 )
        #coil map
        #ut.plotim3(np.absolute(Vim[:,:,im.shape[2]//2,:]),bar = 1)
        #ut.plotim3(np.absolute(sim),bar = 1)
        #create espirit operator
        esp = opts.espirit(Vim)
        #esp.save('../save_data/espirit_data_3d.mat')
        esp.save(path + 'espirit_data_3d.mat')
    else:
        esp = opts.espirit()
        #esp.restore('../save_data/espirit_data_3d.mat')
        esp.restore(path + 'espirit_data_3d.mat')

    #ut.plotim1(np.absolute(mask))#plot the mask
    Aopt = opts.joint2operators(esp, nft)

    #wavelet operator
    dwt = opts.DWTnd(wavelet='haar', level=4)
    #

    scaling = ut.optscaling(Aopt, kdata)
    kdata = kdata / scaling

    #do tv cs mri recon
    #Nite = 20 #number of iterations
    #step = 0.5 #step size
    #tv_r = 0.002 # regularization term for tv term
    #rho  = 1.0
    #xopt = solvers.ADMM_l2Afxnb_tvx( Aopt.forward, Aopt.backward, kdata, Nite, step, tv_r, rho )

    #do wavelet l1 soft thresholding
    Nite = 40  #number of iterations
    step = 0.1  #step size
    th = 0.06  # theshold level
    #xopt = solvers.IST_2( Aopt.forward, Aopt.backward, kdata, Nite, step, th )
    #xopt = solvers.IST_22( Aopt.forward_backward, Aopt.backward, kdata, Nite, step, th )
    #xopt = solvers.FIST_3( Aopt.forward, Aopt.backward, dwt.backward, dwt.forward, kdata, Nite, step, th )
    #xopt = solvers.FIST_32( Aopt.forward_backward, Aopt.backward, dwt.backward, dwt.forward, kdata, Nite, step, th )
    xopt = solvers.FIST_wrap(Aopt, dwt, kdata, Nite, step, th)
    #xopt = solvers.IST_wrap( Aopt, dwt, kdata, Nite, step, th )
    ut.plotim3(np.absolute(xopt[:, :, :]), pause_close=5)
    sio.savemat(path + 'test_im_th0p06.mat', {'xopt': xopt})
Exemplo n.º 9
0
def test():
    ft = opts.FFTnd()
    mat_contents = sio.loadmat(
        '/working/larson/UTE_GRE_shuffling_recon/brain_mt_recon_20160919/brain_3dMRI_32ch.mat'
    )
    x = mat_contents["DATA"]
    #ut.plotim3(np.absolute(x[:,:,:,0]))
    im = ft.backward(x)
    #ut.plotim3(np.absolute(im[:,:,im.shape[2]//2,:]))
    #get shape
    nx, ny, nz, nc = x.shape
    #crop k-space
    xcrop = ut.crop3d(x, 12)
    if 1:  #do espirit
        Vim, sim = espirit_3d(xcrop, x.shape, 150, hkwin_shape = (12,12,12),\
         pad_before_espirit = 0, pad_fact = 2)
        #coil map
        #ut.plotim3(np.absolute(Vim[:,:,im.shape[2]//2,:]),bar = 1)
        #ut.plotim3(np.absolute(sim),bar = 1)
        #create espirit operator
        esp = opts.espirit(Vim)
        #esp.save('../save_data/espirit_data_3d.mat')
        esp.save(
            '/working/larson/UTE_GRE_shuffling_recon/python_test/save_data/espirit_data_3d.mat'
        )
    else:
        esp = opts.espirit()
        #esp.restore('../save_data/espirit_data_3d.mat')
        esp.restore(
            '/working/larson/UTE_GRE_shuffling_recon/python_test/save_data/espirit_data_3d.mat'
        )
    #create mask
    mask = ut.mask3d(nx, ny, nz, [15, 15, 0])
    #FTm  = opts.FFTnd_kmask(mask)
    FTm = opts.FFTWnd_kmask(mask, threads=5)
    #ut.plotim1(np.absolute(mask))#plot the mask
    Aopt = opts.joint2operators(esp, FTm)
    #create image
    im = FTm.backward(x)
    #ut.plotim3(np.absolute(im[:,:,:]))
    #wavelet operator
    dwt = opts.DWTnd(wavelet='haar', level=4)
    # undersampling in k-space
    b = FTm.forward(im)
    scaling = ut.optscaling(FTm, b)
    b = b / scaling
    #ut.plotim3(np.absolute(Aopt.backward(b))) #undersampled imag

    #do tv cs mri recon
    Nite = 20  #number of iterations
    step = 0.5  #step size
    tv_r = 0.002  # regularization term for tv term
    rho = 1.0
    #xopt = solvers.ADMM_l2Afxnb_tvx( Aopt.forward, Aopt.backward, b, Nite, step, tv_r, rho )
    xopt = solvers.ADMM_l2Afxnb_l1Tfx(Aopt.forward, Aopt.backward,
                                      dwt.backward, dwt.forward, b, Nite, step,
                                      tv_r, rho)

    #do wavelet l1 soft thresholding
    #Nite = 50 #number of iterations
    #step = 1 #step size
    #th = 0.4 # theshold level
    #xopt = solvers.FIST_3( Aopt.forward, Aopt.backward, dwt.backward, dwt.forward, b, Nite, step, th )

    ut.plotim3(np.absolute(xopt[:, :, :]))