#----------------------------------------------------------------------- """ Example 09: Reconstruct data using ASTRA ======================================== """ import foam_ct_phantom import astra import numpy as np import h5py import pylab as pl pl.gray() # Run 03_generate_projections_parallel.py and 04_generate_projections_cone first projs = foam_ct_phantom.load_projections('test_projs_par.h5') vol_geom = foam_ct_phantom.VolumeGeometry(256, 256, 256, 3 / 256) proj_geom = foam_ct_phantom.ParallelGeometry.from_file('test_projs_par.h5') pg = proj_geom.to_astra(single_slice=True) vg = vol_geom.to_astra(single_slice=True) pid = astra.create_projector('cuda', pg, vg) w = astra.OpTomo(pid) mid_slice = w.reconstruct('FBP_CUDA', projs[:, projs.shape[1] // 2]) pl.imshow(mid_slice) pl.show()
infiltration_phantom = foam_ct_phantom.InfiltrationFoamPhantom( 'test_infiltration.h5') vol_geom = foam_ct_phantom.VolumeGeometry(256, 256, 1, 3 / 256) infiltration_phantom.generate_volume('test_infiltration_vol_start.h5', vol_geom, time=0) infiltration_phantom.generate_volume('test_infiltration_vol_end.h5', vol_geom, time=1) vol0 = foam_ct_phantom.load_volume('test_infiltration_vol_start.h5') vol1 = foam_ct_phantom.load_volume('test_infiltration_vol_end.h5') pl.imshow(vol0[0]) pl.figure() pl.imshow(vol1[0]) pl.show() proj_geom = foam_ct_phantom.ParallelGeometry( 256, 256, np.linspace(0, 4 * np.pi, 128, False), 3 / 256) infiltration_phantom.generate_projections('test_infiltration_projs.h5', proj_geom) projs = foam_ct_phantom.load_projections('test_infiltration_projs.h5') pl.imshow(projs[0]) pl.figure() pl.imshow(projs[-1]) pl.show()
foam_ct_phantom.FoamPhantom.generate(prefix + 'phantom' + suffix, random_seed, nspheres_per_unit=args.spheres) ### 03 create parallel projection print("Projecting...") phantom = foam_ct_phantom.FoamPhantom(prefix + 'phantom' + suffix) geom = foam_ct_phantom.ParallelGeometry(256, 256, np.linspace(0, np.pi, 128, False), 3 / 256) phantom.generate_projections(prefix + 'proj_par' + suffix, geom) projs = foam_ct_phantom.load_projections(prefix + 'proj_par' + suffix) print(len(projs), "projections, shape", projs.shape) pl.imshow(projs[0]) pl.savefig("projected.png") pl.imshow(projs[3]) pl.savefig("projected3.png") ### 08 add poisson noise print("Adding Noise...") fac = foam_ct_phantom.estimate_absorption_factor(prefix + 'proj_par' + suffix, 0.5) foam_ct_phantom.apply_poisson_noise(input_file=prefix + 'proj_par' + suffix, output_file=prefix + 'proj_noisy' + suffix, seed=1234,
random_seed = 9876 foam_ct_phantom.ExpandingFoamPhantom.generate('test_expand.h5', 'test_phantom.h5', random_seed) expanding_phantom = foam_ct_phantom.ExpandingFoamPhantom('test_expand.h5') vol_geom = foam_ct_phantom.VolumeGeometry(256, 256, 1, 3 / 256) expanding_phantom.generate_volume('test_expand_vol_start.h5', vol_geom, time=0) expanding_phantom.generate_volume('test_expand_vol_end.h5', vol_geom, time=1) vol0 = foam_ct_phantom.load_volume('test_expand_vol_start.h5') vol1 = foam_ct_phantom.load_volume('test_expand_vol_end.h5') pl.imshow(vol0[0]) pl.figure() pl.imshow(vol1[0]) pl.show() proj_geom = foam_ct_phantom.ParallelGeometry( 256, 128, np.linspace(0, 4 * np.pi, 128, False), 3 / 256) expanding_phantom.generate_projections('test_expand_projs.h5', proj_geom) projs = foam_ct_phantom.load_projections('test_expand_projs.h5') pl.imshow(projs[0]) pl.figure() pl.imshow(projs[-1]) pl.show()
#Author: Daniel M. Pelt #Contact: [email protected] #Website: http://dmpelt.github.io/foam_ct_phantom/ #License: MIT # #This file is part of foam_ct_phantom, a Python package for generating #foam-like phantoms for CT. #----------------------------------------------------------------------- """ Example 08: Apply Poission noise to projection data =================================================== """ import foam_ct_phantom import numpy as np import h5py import pylab as pl pl.gray() # Run 03_generate_projections_parallel.py first fac = foam_ct_phantom.estimate_absorption_factor('test_projs_par.h5', 0.5) foam_ct_phantom.apply_poisson_noise('test_projs_par.h5', 'test_projs_noisy.h5', 1234, 100, fac) projs = foam_ct_phantom.load_projections('test_projs_noisy.h5') pl.imshow(projs[0]) pl.show()
import foam_ct_phantom import numpy as np import h5py import astra import matplotlib.pylab as pl import argparse import os pl.gray() parser = argparse.ArgumentParser() parser.add_argument("--file", required=True) args = parser.parse_args() projs = foam_ct_phantom.load_projections(args.file) print(len(projs), "projections, shape", projs.shape) pl.imshow(projs[0]) pl.title("0") pl.show() pl.imshow(projs[10]) pl.title("10") pl.show() pl.imshow(projs[20]) pl.title("20") pl.show()
pl.gray() random_seed = 9876 foam_ct_phantom.MovingFoamPhantom.generate('test_moving.h5', 'test_phantom.h5', random_seed, -0.75, 0.75) moving_phantom = foam_ct_phantom.MovingFoamPhantom('test_moving.h5') vol_geom = foam_ct_phantom.VolumeGeometry(256, 256, 1, 3 / 256) moving_phantom.generate_volume('test_moving_vol_start.h5', vol_geom, time=0) moving_phantom.generate_volume('test_moving_vol_end.h5', vol_geom, time=1) vol0 = foam_ct_phantom.load_volume('test_moving_vol_start.h5') vol1 = foam_ct_phantom.load_volume('test_moving_vol_end.h5') pl.imshow(vol0[0]) pl.figure() pl.imshow(vol1[0]) pl.show() proj_geom = foam_ct_phantom.ParallelGeometry( 256, 128, np.linspace(0, 4 * np.pi, 128, False), 3 / 256) moving_phantom.generate_projections('test_moving_projs.h5', proj_geom) projs = foam_ct_phantom.load_projections('test_moving_projs.h5') pl.imshow(projs[0]) pl.figure() pl.imshow(projs[-1]) pl.show()