vol_geom = astra.create_vol_geom(256, 256) proj_geom = astra.create_proj_geom('parallel', 1.0, 256, np.linspace(0, np.pi, 32, False)) # Create the ASTRA projector (change 'linear' to 'cuda' to use GPU) pid = astra.create_projector('linear', proj_geom, vol_geom) p = astra.OpTomo(pid) # Load the phantom from disk testPhantom = np.load('phantom.npy') # Calculate the forward projection of the phantom testSino = (p * testPhantom).reshape(p.sshape) # Add some noise to the sinogram testSino = astra.add_noise_to_sino(testSino, 10**4) # Reconstruct the image using MR-FBP, FBP, and SIRT. mrRec = p.reconstruct('MR-FBP', testSino) if astra.projector.is_cuda(pid): fbpRec = p.reconstruct('FBP_CUDA', testSino) sirtRec = p.reconstruct('SIRT_CUDA', testSino, 200) else: fbpRec = p.reconstruct('FBP', testSino) sirtRec = p.reconstruct('SIRT', testSino, 200) # Show the different reconstructions on screen import pylab pylab.gray() pylab.subplot(221) pylab.axis('off')
import astra fl = open('example_phantom.json', 'r') strg = fl.read() fl.close() oplist = json.loads(strg) ang = np.linspace(0, np.pi, 256, False) sz = 256 fp, imgs = lorentzphantom.generate.fp(oplist, np.linspace(0, 1, len(ang)), ang, (sz, sz), fpfunc=lorentzphantom.forwproj.astrafp) fp = astra.add_noise_to_sino(fp, 10**3) proj_geom = astra.create_proj_geom('parallel', 1.0, sz, ang) vol_geom = astra.create_vol_geom(sz) pid = astra.create_projector('cuda', proj_geom, vol_geom) w = astra.OpTomo(pid) rec = w.reconstruct('FBP_CUDA', fp, iterations=1) import pylab as pl pl.gray() pl.imshow(fp) pl.show() pl.imshow(rec) pl.show()
na = 32 # Create ASTRA geometries vol_geom = astra.create_vol_geom(nd,nd) proj_geom = astra.create_proj_geom('parallel',1.0,nd,np.linspace(0,np.pi,na,False)) pi = astra.create_projector('linear', proj_geom, vol_geom) # change 'linear' to 'cuda' for GPU p = astra.OpTomo(pi) # Load the phantom from disk testPhantom = phantom.phantom(nd) # Calculate the forward projection of the phantom testSino = (p*testPhantom).reshape((na,nd)) # Add some noise to the sinogram testSino = astra.add_noise_to_sino(testSino,10**3) # Register plugin with ASTRA astra.plugin.register(sirtfbp.plugin) # Reconstruct the image using SIRT-FBP, FBP, and SIRT. sfbpRec = p.reconstruct('SIRT-FBP',testSino,200, extraOptions={'filter_dir':os.getcwd()}) if astra.projector.is_cuda(pi): fbpRec = p.reconstruct('FBP_CUDA',testSino) sirtRec = p.reconstruct('SIRT_CUDA',testSino,200) else: fbpRec = p.reconstruct('FBP',testSino) sirtRec = p.reconstruct('SIRT',testSino,200) # Show the different reconstructions on screen import pylab
# Create the ASTRA projector pid = astra.create_projector('linear',proj_geom,vol_geom) # change 'linear' to 'cuda' to use GPU p = astra.OpTomo(pid) # Create simulated HQ dataset for training hq = np.zeros((ns,nd,nd)) hq[:,nd//4:3*nd//4,nd//4:3*nd//4]=1 hq[:,3*nd//8:5*nd//8,3*nd//8:5*nd//8]=0 try: os.mkdir('hqrecs/') except OSError: pass projections = np.zeros((ns, na, nd)) for i in range(ns): projections[i] = astra.add_noise_to_sino((p*hq[i]).reshape(p.sshape),i0) tifffile.imsave('hqrecs/{:04d}.tiff'.format(i),hq[i]) # Prepare training files astra.plugin.register(nnfbp.plugin_prepare) try: os.mkdir('trainfiles/') except OSError: pass for i in range(ns): p.reconstruct('NN-FBP-prepare',projections[i],extraOptions={'hqrecfiles':'hqrecs/*.tiff','z_id':i,'traindir':'trainfiles/','npick':1000}) # Train filters and weights nnfbp.plugin_train('trainfiles/', 4, 'filters.mat') # Generate test sinogram
import lorentzphantom import numpy as np import json import astra fl = open('example_phantom.json','r') strg = fl.read() fl.close() oplist = json.loads(strg) ang = np.linspace(0,np.pi,256,False) sz = 256 fp,imgs = lorentzphantom.generate.fp(oplist,np.linspace(0,1,len(ang)),ang,(sz,sz), fpfunc=lorentzphantom.forwproj.astrafp) fp = astra.add_noise_to_sino(fp,10**3) proj_geom = astra.create_proj_geom('parallel',1.0,sz,ang) vol_geom = astra.create_vol_geom(sz) pid = astra.create_projector('cuda',proj_geom,vol_geom) w = astra.OpTomo(pid) rec = w.reconstruct('FBP_CUDA',fp,iterations=1) import pylab as pl pl.gray() pl.imshow(fp) pl.show() pl.imshow(rec) pl.show()
import numpy as np import astra # Simple phantom x = np.zeros((1024,1024)) x[400:600,400:600]=1 # ASTRA geometries, projector, and OpTomo proj_geom = astra.create_proj_geom('parallel',1.0,1024,np.linspace(0,np.pi,180)) vol_geom = astra.create_vol_geom(1024) pid = astra.create_projector('cuda',proj_geom,vol_geom) p = astra.OpTomo(pid) # Create sinogram and add noise sino = (p*x).reshape(p.sshape) sino_with_noise = astra.add_noise_to_sino(sino,10**2) # Define parameters and FISTA object that performs reconstruction lam = 2**-5 f = tvtomo.FISTA(p,lam,100) # Actually reconstruct (takes time) tvrec = f.reconstruct(sino_with_noise,50, progress=True) # ASTRA data for reconstructions below sid = astra.data2d.create('-sino', proj_geom,sino_with_noise) rid = astra.data2d.create('-vol', vol_geom) #ASTRA SIRT cfg = astra.astra_dict('SIRT_CUDA') cfg['ProjectionDataId'] = sid
import astra # Simple phantom x = np.zeros((1024, 1024)) x[400:600, 400:600] = 1 # ASTRA geometries, projector, and OpTomo proj_geom = astra.create_proj_geom('parallel', 1.0, 1024, np.linspace(0, np.pi, 180)) vol_geom = astra.create_vol_geom(1024) pid = astra.create_projector('cuda', proj_geom, vol_geom) p = astra.OpTomo(pid) # Create sinogram and add noise sino = (p * x).reshape(p.sshape) sino_with_noise = astra.add_noise_to_sino(sino, 10**2) # Define parameters and FISTA object that performs reconstruction lam = 2**-5 f = tvtomo.FISTA(p, lam, 100) # Actually reconstruct (takes time) tvrec = f.reconstruct(sino_with_noise, 50, progress=True) # ASTRA data for reconstructions below sid = astra.data2d.create('-sino', proj_geom, sino_with_noise) rid = astra.data2d.create('-vol', vol_geom) #ASTRA SIRT cfg = astra.astra_dict('SIRT_CUDA') cfg['ProjectionDataId'] = sid
pid = astra.create_projector('linear', proj_geom, vol_geom) # change 'linear' to 'cuda' to use GPU p = astra.OpTomo(pid) # Create simulated HQ dataset for training hq = np.zeros((ns, nd, nd)) hq[:, nd // 4:3 * nd // 4, nd // 4:3 * nd // 4] = 1 hq[:, 3 * nd // 8:5 * nd // 8, 3 * nd // 8:5 * nd // 8] = 0 try: os.mkdir('hqrecs/') except OSError: pass projections = np.zeros((ns, na, nd)) for i in range(ns): projections[i] = astra.add_noise_to_sino((p * hq[i]).reshape(p.sshape), i0) tifffile.imsave('hqrecs/{:04d}.tiff'.format(i), hq[i]) # Prepare training files astra.plugin.register(nnfbp.plugin_prepare) try: os.mkdir('trainfiles/') except OSError: pass for i in range(ns): p.reconstruct('NN-FBP-prepare', projections[i], extraOptions={ 'hqrecfiles': 'hqrecs/*.tiff', 'z_id': i, 'traindir': 'trainfiles/',