def test(): # simulated image mat_contents = sio.loadmat('data/kellman_data/PKdata3.mat', struct_as_record=False, squeeze_me=True) xdata = mat_contents["data"] im = xdata.images field = xdata.FieldStrength b0_gain = 100.0 TE = b0_gain * xdata.TE fat_freq_arr = (1.0 / b0_gain) * 42.58 * field * np.array( [-3.80, -3.40, -2.60, -1.94, -0.39, 0.60]) fat_rel_amp = np.array([0.087, 0.693, 0.128, 0.004, 0.039, 0.048]) #ut.plotim3(np.real(im[:,:,:])) nx, ny, nte = im.shape #undersampling mask = ut.mask3d(nx, ny, nte, [15, 15, 0], 0.8) #FTm = opts.FFT2d_kmask(mask) FTm = opts.FFTW2d_kmask(mask) #FTm = opts.FFT2d() b = FTm.forward(im) scaling = ut.optscaling(FTm, b) b = b / scaling #ut.plotim3(mask) #ut.plotim3(np.absolute(FTm.backward(b))) #undersampled imag #parameters xpar = np.zeros((nx, ny, 3), np.complex128) #xpar[:,:,0] = 10*np.ones((nx,ny)) #ut.plotim3(np.absolute(xpar),[3,-1]) # IDEAL and FFT jointly IDEAL = idealc.IDEAL_opt2(TE, fat_freq_arr, fat_rel_amp) #fat_freq_arr , fat_rel_amp Aideal_ftm = opts.joint2operators(IDEAL, FTm) #(FTm,IDEAL)# IDEAL.set_x(xpar) #this set the size of data dwt = opts.DWT2d(wavelet='haar', level=4) #do tv cs mri recon Nite = 10 #number of iterations step = 1 #step size l1_r = 0.001 tv_r = 0.0001 # regularization term for tv term rho = 1.0 xpar = ADMM_l2Agaussnewton_l1Tfx(IDEAL, FTm, dwt, b, Nite, step, l1_r, rho) #xpar = ADMM_l2Aguassnewton_tvx(IDEAL, FTm, b, Nite, step, tv_r, rho ) #xpar = ADMM_l2Agaussnewton_l1Tfx_tvx( IDEAL, FTm, dwt, b, Nite, step, l1_r, tv_r, rho) ut.plotim3(np.absolute(xpar)[..., 0:2], bar=1) ut.plotim3(b0_gain * np.real(xpar)[..., 2], bar=1) ut.plotim3(b0_gain * 2.0 * np.pi * np.imag(xpar)[..., 2], bar=1)
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))
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[:, :, :]))
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