def setUp(**kwargs): if kwargs.get('mode') == 'cone': geo = tigre.geometry(mode='cone', nVoxel=kwargs.get('nVoxel'), default_geo=True) angles_1 = np.linspace(0, 2 * np.pi, 100, dtype=np.float32) angles_3 = np.zeros((100), dtype=np.float32) angles = np.vstack((angles_1, angles_3, angles_3)).T img = data_loader.load_head_phantom(number_of_voxels=geo.nVoxel) proj = tigre.Ax(img, geo, angles, kwargs.get('krylov')) if kwargs.get('alglist') == 'all': alglist = ['sart', 'sirt', 'ossart', 'asd_pocs', 'FDK', 'cgls'] else: alglist = kwargs.pop('alglist').split() plot_algs(alglist, proj, geo, angles, niter=int(kwargs.pop('niter')), **kwargs) if kwargs.get('mode') == 'parallel': geo = tigre.geometry(mode='parallel', nVoxel=kwargs.get('nVoxel'), default_geo=True) angles_1 = np.linspace(0, 2 * np.pi, 100, dtype=np.float32) angles_3 = np.zeros((100), dtype=np.float32) angles = np.vstack((angles_1, angles_3, angles_3)).T img = data_loader.load_head_phantom(number_of_voxels=geo.nVoxel) proj = tigre.Ax(img, geo, angles, kwargs.get('krylov')) if kwargs.get('alglist') == 'all': alglist = ['sart', 'sirt', 'ossart', 'asd_pocs', 'fbp', 'cgls'] else: alglist = kwargs.pop('alglist').split() plot_algs(alglist, proj, geo, angles, niter=int(kwargs.pop('niter')), **kwargs)
def setUp(**kwargs): if kwargs.get('mode') == 'cone': geo = tigre.geometry(mode='cone', nVoxel=kwargs.get('nVoxel'), default_geo=True) angles_1 = np.linspace(0, 2 * np.pi, 100, dtype=np.float32) angles_3 = np.zeros((100), dtype=np.float32) angles = np.vstack((angles_1, angles_3, angles_3)).T img = data_loader.load_head_phantom(number_of_voxels=geo.nVoxel) proj = tigre.Ax(img, geo, angles, kwargs.get('krylov')) if kwargs.get('alglist') == 'all': alglist = ['sart', 'sirt', 'ossart', 'asd_pocs', 'FDK', 'cgls'] else: alglist = kwargs.pop('alglist').split() plot_algs(alglist, proj, geo, angles, niter=int(kwargs.pop('niter')), **kwargs) if kwargs.get('mode') == 'parallel': geo = tigre.geometry(mode='parallel', nVoxel=kwargs.get('nVoxel'), default_geo=True) angles_1 = np.linspace(0, 2 * np.pi, 100, dtype=np.float32) angles_3 = np.zeros((100), dtype=np.float32) angles = np.vstack((angles_1, angles_3, angles_3)).T img = data_loader.load_head_phantom(number_of_voxels=geo.nVoxel) proj = tigre.Ax(img, geo, angles, kwargs.get('krylov')) if kwargs.get('alglist') == 'all': alglist = ['sart', 'sirt', 'ossart', 'asd_pocs', 'fbp', 'cgls'] else: alglist = kwargs.pop('alglist').split() plot_algs(alglist, proj, geo, angles, niter=int(kwargs.pop('niter')), **kwargs)
def configuration2(alg): try: geo = tigre.geometry(mode='parallel', nVoxel=nVoxel, default_geo=True) niter = 10 nangles = 100 angles_1 = np.linspace(0, 2 * np.pi, nangles, dtype=np.float32) angles_2 = np.zeros((nangles), dtype=np.float32) angles = np.vstack((angles_1, angles_2, angles_2)).T testandlog([alg], geo, angles, niter, saveresult=True, subdirectoryname='configuration2', sup_kw_warning=True) except Exception as e: print(traceback.format_exc()) raise SystemExit()
def setUp(self): geo = tigre.geometry() geo.DSD = 1536 geo.DSO = 1000 geo.nDetector = np.array((128, 127)) geo.dDetector = np.array((0.8, 0.8)) * 4. geo.sDetector = geo.nDetector * geo.dDetector geo.nVoxel = np.array((63, 62, 61)) geo.sVoxel = np.array((256, 256, 256)) geo.dVoxel = geo.sVoxel / geo.nVoxel geo.offOrigin = np.array((0, 0, 0)) geo.offDetector = np.array((0, 0)) geo.accuracy = 0.5 geo.mode = 'cone' self.angles = np.linspace(0, 2 * np.pi, 100, dtype=np.float32) self.geo = geo self.img = np.ones((63, 62, 61), dtype=np.float32) self.proj = Ax(self.img,self.geo,self.angles) self.niter=2
niter = 20 dirname = os.path.dirname(__file__) keywords = dict(blocksize=20, hyper = 9.391252e+06) def save_config(dict, name): for kw in dict: if kw not in ['nproj', 'geo', 'angles', 'niter', 'kwargs']: raise KeyError() np.save(os.path.join(dirname, name), dict) if __name__ == '__main__': geo = tigre.geometry(mode='cone', nVoxel=nVoxel, default=True) # (V,U) number of pixels (px) geo.nDetector = np.array((256, 256)) # size of each pixel (mm) geo.dDetector = np.array((0.8, 0.8))*2 geo.sDetector = geo.nDetector * geo.dDetector save_config(dict( nproj=100, niter=20, geo=geo, angles=np.linspace(0, 2 * np.pi, 100), kwargs=keywords ), 'configuration1.npy')
class TestStdout(unittest.TestCase): pass def test_generator(algorithm, proj, geo, angles, niter): def test(self): capturedOutput = StringIO.StringIO() sys.stdout = capturedOutput getattr(algs, algorithm)(proj, geo, angles, niter=niter, verbose=False) self.assertIs(capturedOutput.getvalue(), "") sys.stdout = sys.__stdout__ return test if __name__ == "__main__": geo = tigre.geometry(mode="cone", default=True, high_quality=False) print(geo) true_img = data_loader.load_head_phantom(geo.nVoxel) angles = np.linspace(0, 2 * np.pi, 100) niter = 5 proj = tigre.Ax(true_img, geo, angles) for alg in algs.__all__: if alg != "fbp": test_name = "test_print_%s" % (alg) test = test_generator(alg, proj, geo, angles, niter) setattr(TestStdout, test_name, test) unittest.main()
from tigre.utilities import gpu listGpuNames = gpu.getGpuNames() if len(listGpuNames) == 0: print("Error: No gpu found") else: for id in range(len(listGpuNames)): print("{}: {}".format(id, listGpuNames[id])) gpuids = gpu.getGpuIds(listGpuNames[0]) print(gpuids) # Geometry #geo1 = tigre.geometry(mode='cone', high_quality=False, default=True) geo = tigre.geometry(mode='cone', nVoxel=np.array([256, 256, 256]), default=True) geo.dDetector = np.array([0.8, 0.8]) * 2 # size of each pixel (mm) geo.sDetector = geo.dDetector * geo.nDetector # print(geo) nangles = 100 angles = np.linspace(0, 2 * np.pi, nangles, endpoint=False, dtype=np.float32) # Prepare projection data #head = np.load('src_img_cubic_256.npy') head = data_loader.load_head_phantom(geo.nVoxel) proj = tigre.Ax(head, geo, angles, gpuids=gpuids) # Reconstruct niter = 20
# Codes: https://github.com/CERN/TIGRE/ # Coded by: Ander Biguri # -------------------------------------------------------------------------- #%%Initialize import tigre import numpy as np from tigre.utilities import sample_loader from tigre.utilities import CTnoise import tigre.algorithms as algs #%% Geometry # While you can defien you rown geometry, the easiest way is: # just give as nVoxel the same number as your projection size. geo = tigre.geometry( mode="parallel", nVoxel=np.array([512, 512, 512]) ) # Parallel beam geometry does not require anything other than the image size. #%% Load data and generate projections # define angles angles = np.linspace(0, 2 * np.pi, 100) # Load thorax phatom data head = sample_loader.load_head_phantom(geo.nVoxel) # generate projections projections = tigre.Ax(head, geo, angles) # add noise noise_projections = CTnoise.add(projections, Poisson=1e5, Gaussian=np.array([0, 10])) # recon
import tigre import tigre.algorithms as algs import numpy as np geo = tigre.geometry(mode='cone', nVoxel=np.array([32, 64, 128]), default_geo=True) from tigre.demos.Test_data import data_loader img = data_loader.load_head_phantom(geo.nVoxel) angles = np.linspace(0, np.pi * 2, 100, dtype=np.float32) proj = tigre.Ax(img, geo, angles) algs.fdk(proj, geo, angles)
do_algs(alglist, proj_con, geo_con, angles, mode='cone', niter=20, **dict(nVoxel = nVoxel, blocksize=20)) # --------------------------- CGLS for both modes--------------------------------------- do_algs(['cgls'], proj_par, geo_par, angles, mode='Parallel', **dict(nVoxel = [64 ,64 ,64])) do_algs(['cgls'], proj_con, geo_con, angles, mode='Cone', **dict(nVoxel = [64 ,64 ,64])) """ import tigre.algorithms as algs nangles = 100 angles_1 = np.linspace(0, 2 * np.pi, nangles, dtype=np.float32) angles_2 = np.ones( (nangles), dtype=np.float32) * np.array(np.pi / 4, dtype=np.float32) angles_3 = np.zeros((nangles), dtype=np.float32) angles = np.vstack((angles_1, angles_3, angles_3)).T geo = tigre.geometry(mode='cone', nVoxel=nVoxel, default_geo=True) source_img = data_loader.load_head_phantom(number_of_voxels=geo.nVoxel) proj = tigre.Ax(source_img, geo, angles) res = algs.awasd_pocs(proj, geo, angles, niter=10, **dict(blocksize=nangles)) from matplotlib import pyplot as plt plt.imshow(res[32]) plt.show() """ from tigre.utilities.Atb import Atb Atb(proj,geo,angles,'FDK')[32] #plt.colorbar() #plt.title('FDK') mat = Atb(proj,geo,angles,'matched') plt.subplot(221) plt.imshow(mat[32]) plt.subplot(222)
0, -geo.sVoxel[1] / 2 if idx == 0 else geo.sVoxel[1] / 2, 0 ]) + offOrigin, ) plt.show() if __name__ == "__main__": n_voxel_z = 128 n_voxel_y = 256 n_voxel_x = 512 n_detector_u = 400 n_detector_v = 300 off_detector_u = 0 # 500 off_detector_v = 0 # 500 off_origin_x = 0 # 300 off_origin_y = 0 # 100 off_origin_z = 0 # 100 geo = tigre.geometry(mode="cone", default=True) geo.nVoxel = np.array([n_voxel_z, n_voxel_y, n_voxel_x]) geo.sVoxel = geo.nVoxel geo.dVoxel = geo.sVoxel / geo.nVoxel geo.nDetector = np.array([n_detector_v, n_detector_u]) geo.sDetector = geo.nDetector * geo.dDetector geo.offDetector = np.array([off_detector_v, off_detector_u]) geo.offOrigin = np.array([off_origin_z, off_origin_y, off_origin_x]) print(geo) angle = -np.pi / 6 plot_geometry(geo, angle)
import sys import tigre import numpy as np from matplotlib import pyplot as plt from tigre.demos.Test_data import data_loader from tigre.utilities.Ax import Ax import tigre.algorithms as algs from tigre.algorithms.iterative_recon_alg import IterativeReconAlg #----------------PROFILINGIMPORT------------------- from line_profiler import LineProfiler # ---------------GEOMETRY--------------------------- geo = tigre.geometry(mode='parallel',nVoxel = np.array([64,64,64])) source_img = data_loader.load_head_phantom(number_of_voxels=geo.nVoxel) # ---------------------ANGLES------------------------- angles_1 = np.linspace(0, 2 * np.pi, 100, dtype=np.float32) angles_2 = np.ones((100), dtype=np.float32) * np.array(np.pi / 4, dtype=np.float32) angles_3 = np.zeros((100), dtype=np.float32) angles = np.vstack((angles_1, angles_3, angles_3)).T # --------------------PROJECTION---------------------- proj = Ax(source_img,geo,angles) # ---------------------RECONSTRUCTION------------------
from __future__ import print_function import tigre import numpy as np import tigre.demos.Test_data.data_loader as data_loader from tigre.algorithms.conjugate_gradient_algorithms import CGLS from tigre.algorithms.pocs_algorithms import ASD_POCS from tigre.algorithms.art_family_algorithms import SART from matplotlib import pyplot as plt import tigre import tigre.algorithms as algs from tigre.utilities.Ax import Ax # ---------------GEOMETRY--------------------------- geo = tigre.geometry(mode='parallel', nVoxel=np.array([64, 64, 64], dtype=np.float32)) source_img = data_loader.load_head_phantom(number_of_voxels=geo.nVoxel) # ---------------------ANGLES------------------------- angles_1 = np.linspace(0, 2 * np.pi, 100, dtype=np.float32) angles_2 = np.ones( (100), dtype=np.float32) * np.array(np.pi / 4, dtype=np.float32) angles_3 = np.zeros((100), dtype=np.float32) angles = np.vstack((angles_1, angles_3, angles_3)).T # --------------------PROJECTION---------------------- from tigre.demos.__test import test test() """ # --------------------BACK PROJECTION ----------------
#%% Geometry class: # -nVoxel: 3x1 array of number of voxels in the image # -sVoxel: 3x1 array with the total size in mm of the image # -dVoxel: 3x1 array with the size of each of the voxels in mm # -nDetector: 2x1 array of number of voxels in the detector plane # -sDetector: 2x1 array with the total size in mm of the detector # -dDetector: 2x1 array with the size of each of the pixels in the detector in mm # -DSD: 1x1 or 1xN array. Distance Source Detector, in mm # -DSO: 1x1 or 1xN array. Distance Source Origin. # -offOrigin: 3x1 or 3xN array with the offset in mm of the centre of the image from the origin. # -offDetector: 2x1 or 2xN array with the offset in mm of the centre of the detector from the x axis # -rotDetector: 3x1 or 3xN array with the rotation in roll-pitch-yaw of the detector #%% Example # # Lets create a geomtry object geo = tigre.geometry() # VARIABLE DESCRIPTION UNITS # ------------------------------------------------------------------------------------- # Distances geo.DSD = 1536 # Distance Source Detector (mm) geo.DSO = 1000 # Distance Source Origin (mm) # Detector parameters geo.nDetector = np.array([512, 512]) # number of pixels (px) geo.dDetector = np.array([0.8, 0.8]) # size of each pixel (mm) geo.sDetector = geo.nDetector * geo.dDetector # total size of the detector (mm) # Image parameters geo.nVoxel = np.array([256, 256, 256]) # number of voxels (vx) geo.sVoxel = np.array([256, 256, 256]) # total size of the image (mm) geo.dVoxel = geo.sVoxel / geo.nVoxel # size of each voxel (mm) # Offsets geo.offOrigin = np.array([0, 0, 0]) # Offset of image from origin (mm)
import sys # TODO: this is quite nasty; it would be nice to reorganise file structure later so top level folder is always in path currDir = os.path.dirname(os.path.realpath(__file__)) rootDir = os.path.abspath(os.path.join(currDir, '..')) if rootDir not in sys.path: # add parent dir to paths sys.path.append(rootDir) import numpy as np import tigre.geometry_default as geometry import Test_data.data_loader as data_loader import scipy.io from tigre.utilities.plotproj import plotproj from _Ax import Ax TIGRE_parameters = geometry(high_quality=False) head = data_loader.load_head_phantom(number_of_voxels=TIGRE_parameters.nVoxel) angles = np.linspace(0, 2 * np.pi, 20, dtype=np.float32) # angles = np.linspace(0, 0, 1, dtype=np.float32) # What is expected to happen here is the memory allocated for the head image is given to the C functions to operate on # Whilst it will return newly allocated PYTHON(!) memory for each projection; expected to be allocated from C and parsed # back into python # I believe it should be ok to just parse geometry each time until we find a way of passing around a C array in python projections = Ax(head, TIGRE_parameters, angles, 'interpolated') plotproj(projections)
from __future__ import print_function import tigre import copy import tigre.algorithms as algs import numpy as np import tigre.algorithms as algs from tigre.demos.Test_data import data_loader from matplotlib import pyplot as plt geo = tigre.geometry(mode='cone', nVoxel=np.array([64, 64, 62]), default_geo=True) niter = 10 nangles = 100 angles = np.linspace(0, 2 * np.pi, nangles, dtype=np.float32) #angles_2 = np.zeros((nangles, ), dtype=np.float32) #angles_3 = np.ones((nangles, ), dtype=np.float32) #angles = np.vstack((angles_1, angles_2, angles_3)).T head = data_loader.load_head_phantom(geo.nVoxel) proj = tigre.Ax(head,geo,angles) output = algs.sart(proj,geo,angles,niter=5) plt.imshow(output[geo.nVoxel[0]/2]) plt.colorbar() plt.show()
proj,geo, angles = tigreio.BrukerDataLoader(datafolder,dataset_num=0) # load the first #%% DICOM data (only tested on Philips Allura) ######## TODO #%% Generic # It is possible that your scanner is not currently supported, or that it # simply does not have any way of storing the information (Zeiss Xradia # does not store anything but the projecions) # if this is the case, the general way of tackling the problem is: # Step 1: define your geometry and angles geo=tigre.geometry() angles= # Step 2: Load projections: #store in NP array. Use whichever python lirbary will help you get the data loaded. # Step 3: validate tigre.plotproj(proj,angles) # you need to make sure that: # 1) white=metal/bone/high density and black=air. # If this is not the case proj=-np.log(proj/(np.max(proj+1)); # Beer-Lanbert law # 2) rotation happens left-right instead of top-bottom. # If its top bottom permute your data as required
import tigre import numpy as np from matplotlib import pyplot as plt from tigre.demos.Test_data import data_loader from tigre.utilities.Ax import Ax import tigre.algorithms as algs from tigre.algorithms.iterative_recon_alg import IterativeReconAlg # ----------------PROFILINGIMPORT------------------- from line_profiler import LineProfiler # ---------------GEOMETRY--------------------------- geo = tigre.geometry(mode='parallel', nVoxel=np.array([64, 64, 64])) source_img = data_loader.load_head_phantom(number_of_voxels=geo.nVoxel) # ---------------------ANGLES------------------------- angles_1 = np.linspace(0, 2 * np.pi, 100, dtype=np.float32) angles_2 = np.ones((100), dtype=np.float32) * np.array(np.pi / 4, dtype=np.float32) angles_3 = np.zeros((100), dtype=np.float32) angles = np.vstack((angles_1, angles_3, angles_3)).T # --------------------PROJECTION---------------------- proj = Ax(source_img, geo, angles) # ---------------------RECONSTRUCTION------------------