def test2(): N = 20 k1, k2, k3 = nufftfreqs3d(N, N, N) k_c = np.cos(np.multiply(5, k1)) + 1j * np.sin(np.multiply(5, k2)) # #k_c = np.ones((N,N,N))# hwin = hamming3d(N, N, N) ut.plotim3(np.absolute(hwin), [4, -1]) # apply hamming window k_c = np.multiply(k_c, hwin) im = dft3d_warp(N, N, N, k_c) ut.plotim3(np.absolute(im), [4, -1], bar=True) #use std fft lib ft = opts.FFTnd() npim = ft.backward(k_c) ut.plotim3(np.absolute(npim), [4, -1], bar=True) ut.plotim3(np.absolute(im - npim), [4, -1], bar=True) #interpolatation im_int = dft3d_warp(2 * N, 2 * N, N, k_c) ut.plotim3(np.absolute(im_int), [4, -1], bar=True)
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, :]))
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})
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[:, :, :]))