""" Compare the accuracy of reconstructions made from projections taken over 180 degrees with ones taken over 90 degrees. """ import astra1 import matplotlib.pyplot as plt import numpy as np import phantoms import offset90_v2 import graphs #create phantom jet = phantoms.shockjet(129, 800, 4, 2000, 6) s1 = astra1.sinogram(jet, np.pi, 180) s2 = astra1.sinogram(jet, np.pi / 2, 90) s3 = offset90_v2.mirror_sinogram(s2) graphs.colourmap(s1) graphs.colourmap(s2) graphs.colourmap(s3) graphs.colourmap(s1 - s3) # reconstruct for different amount of angles and plot the average discrepancy.. # .. from the phantom jet #ang_discrepancy = [] #angles = range(2,50,10) # range of different number of angles to take projections at #for a in angles: # s1 = astra1.sinogram(jet, np.pi, a) # r1 = astra1.reconstruct(s1, 'SIRT', 100)
def resize(r, d): # resizes the reconstruction to the desired size # r is the reconstruction # d is the desired size resized = np.zeros((d, d)) start = int((r.shape[0] - d) / 2) resized = r[start + 2:start + d + 2, start:start + d] return resized if __name__ == "__main__": j = phantoms.offset_jet(0, 0) sino = astra1.sinogram(j, np.pi / 2, 180) # make offset jet ofsj = phantoms.offset_jet(48, 55) graphs.colourmap(ofsj) plt.title('Original phantom') # take projections and make sinogram offsino = astra1.sinogram(ofsj, np.pi / 2, 180) graphs.colourmap(offsino) plt.title('90 degrees sinogram') # straighten offsino = centre_sino(offsino) #, np.pi/2, 48, 55) graphs.colourmap(offsino) plt.title('Line of symmetry through axis of rotation')
def supergaussianjet(n, s, p): # n is dimenstions of array (128) # s is the standard deviation of the gaussian # p is the power in the exponent of the super-gaussian s2 = s * s x, y = np.meshgrid(range(int(-n / 2), int(n / 2), 1), range(int(-n / 2), int(n / 2), 1)) rp = (x * x + y * y)**(p / 2) return np.array(np.exp(-rp / (2 * s2))) if __name__ == "__main__": jet = shockjet(129, 800, 4, 2000, 6) graphs.colourmap(jet) sino = astra1.sinogram(jet, np.pi, 180) graphs.colourmap(sino) reconstruction = astra1.reconstruct(sino, 'SIRT', 40, np.pi) graphs.colourmap(reconstruction) """ offset = offset_bar(10,20) graphs.colourmap(offset) sino = astra1.sinogram(offset, np.pi, 180) #graphs.colourmap(sino) """ #gaussian = gaussianjet(128,800) #graphs.colourmap(gaussian) #sino = astra1.sinogram(gaussian, np.pi, 180) #graphs.colourmap(sino) #graphs.plot3d(gaussian)
ang_discrepancy_no_noise = [] ang_discrepancy_poisson_noise = [] ang_discrepancy_sandp_noise = [] ang_discrepancy_gaussian_noise = [] angles = range(1,90)#range of different number of angles to take projections at num_iterations = 15 alg ='FBP' poi = False sandp = False gauss = True for a in angles: # a is number of angles used to get sinogram #print(a, 'angles') sinogram_ = astra1.sinogram(jet, np.pi, a, poi, sandp, gauss) sinogram_correct_units = real_units.num_density(sinogram_) reconstruction = astra1.reconstruct(sinogram_correct_units, alg, num_iterations) d = (np.mean(abs(jet_correct_units - reconstruction)) / np.mean(jet_correct_units)) *100 if poi == True: ang_discrepancy_poisson_noise.append(d) if sandp == True: ang_discrepancy_sandp_noise.append(d) if gauss == True: ang_discrepancy_gaussian_noise.append(d) if [poi,gauss,sandp] == [False,False,False]:
To investigate the accuracy of the reconstruction with different numbers of iterations. """ import astra1 import matplotlib.pyplot as plt import numpy as np import phantoms import pylab #create phantom jet = phantoms.shockjet(129, 800, 4, 2000, 6) # reconstruct for different number of iterations and plot the average discrepancy.. # .. from the phantom jet iterations = range( 1, 40) # range of different number of iterations to reconstruct with iter_discrepancy = [] alg = 'SIRT' for i in iterations: # i is number of iterations used to get reconstruction print(i, 'iterations') s = astra1.sinogram(jet, np.pi, 90) r = astra1.reconstruct(s, alg, i) e = np.mean(abs(jet - r)) / np.mean(jet) * 100 iter_discrepancy.append(e) plt.figure() plt.plot(iterations, iter_discrepancy) plt.xlabel('Number of iterations for reconstruction') plt.ylabel('Average discrepancy relative to average phantom value (%)') #pylab.ylim(0,50)
plt.figure(10) diff_phant_clean = (phant_centr - reconstruction_clean) diff_phant_noise = (phant_centr - reconstruction_noise) plt.title('Lineout of the difference between the phantom and the reconstruction.') graphs.lineout(diff_phant_clean) graphs.lineout(diff_phant_noise) """ for n in n_iterations: print(n,'iterations') # find the different reconstructions of the phantom print('Noise') sino_noise = astra1.sinogram(phant_centr, np.pi, n_projections, gaussian_noise=True, s_and_p_noise=True) fbp_noise = astra1.reconstruct(sino_noise, 'FBP', n) sirt_noise = astra1.reconstruct(sino_noise, 'SIRT', n) print('Clean') sino_clean = astra1.sinogram(phant_centr, np.pi, n_projections) fbp_clean = astra1.reconstruct(sino_clean, 'FBP', n) sirt_clean = astra1.reconstruct(sino_clean, 'SIRT', n) print('90 Clean') sino_90 = astra1.sinogram(phant_centr, np.pi/2, n_projections) #sino_90 = offset90_v2_29_11.centre_sino(sino_90) sino_90 = offset90_v2_29_11.mirror_sinogram(sino_90) fbp_90 = astra1.reconstruct(sino_90, 'FBP', n, np.pi) #fbp_90 = offset90_v2_29_11.resize(fbp_90, 129) sirt_90 = astra1.reconstruct(sino_90, 'SIRT', n, np.pi)
sino_mirr = np.zeros((2*num_angles,s.shape[1])) sino_mirr[0:num_angles, 0:s.shape[1]] += s sinogram2 = np.flip(s,0) sino_mirr[num_angles:2*num_angles, 0:s.shape[1]] += sinogram2[0:] return sino_mirr if __name__ == '__main__': #create phantom jet = phantoms.shockjet(129,800,4,2000,6) # create sinogram from phantom num_angles = 90 sinogram90 = astra1.sinogram(jet, np.pi/2, num_angles) sino_mirr = mirror_sinogram(sinogram90) # image of sinogram imageio.imwrite('sino_mirr.png', sino_mirr) graphs.colourmap(sino_mirr) sinogram180 = astra1.sinogram(jet, np.pi, 2*num_angles) ## image of the full proper sinogram imageio.imwrite('sinogram180.png', sinogram180) # difference of sinogram from 90 and the normal 180 sino_diff = sinogram180 - sino_mirr
import imageio import numpy as np import real_units import phantoms #create phantom jet = phantoms.shockjet(129, 800, 4, 2000, 6) #create phantom with correct units jet_correct_units = real_units.num_density(jet) # above is commented out as messes with reconstruction scaling issues - FIXED #above is commented out as messes with addition of noise # create sinogram from phantom sinogram_ = astra1.sinogram(jet, np.pi, 180, False, False, True) #sinogram__= astra1.sinogram(jet_correct_units,np.pi,180,True) sinogram_correct_units = real_units.num_density(sinogram_) """ # create sinogram with noise from phantom sinogram_poisson_noise = astra1.sinogram_poisson(,sinogram,jet, np.pi, 180) sinogram_poisson_s_and_p = astra1.add_salt_pepper(jet_correct_units,np.pi,180,0.01) """ # create reconstruction reconstruction = astra1.reconstruct(sinogram_correct_units, 'FBP', 100) # birds eye view of phantom imageio.imwrite("shockjet_phantom.png", jet_correct_units)
# d is the desired size resized = np.zeros((d, d)) start = int((r.shape[0] - d) / 2) resized = r[start + 2:start + d + 2, start:start + d] return resized if __name__ == "__main__": # make offset jet ofsj = phantoms.offset_jet(48, 55) graphs.colourmap(ofsj) plt.title('Original phantom') # take projections and make sinogram offsino = astra1.sinogram(ofsj, np.pi / 2, 90) graphs.colourmap(offsino) plt.title('90 degrees sinogram') # straighten offsino = centre_sino(offsino) #, np.pi/2, 48, 55) graphs.colourmap(offsino) plt.title('Line of symmetry through axis of rotation') # mirror offsino = mirror_sinogram(offsino) graphs.colourmap(offsino) plt.title('Mirrored to 180 degrees') # reconstruction off_recon = astra1.reconstruct(offsino, 'FBP', 100, np.pi)
fbp_noise_err = [] sirt_noise_err = [] fbp_clean_err = [] sirt_clean_err = [] fbp_90_err = [] sirt_90_err = [] fbp_90_noise_err = [] sirt_90_noise_err = [] for n in n_projections: print(n,'projections') # find the different reconstructions of the phantom print('Noise') sino_noise = astra1.sinogram(phant, np.pi, n, gaussian_noise=True) fbp_noise = astra1.reconstruct(sino_noise, 'FBP', n_iterations) sirt_noise = astra1.reconstruct(sino_noise, 'SIRT', n_iterations) print('Clean') sino_clean = astra1.sinogram(phant, np.pi, n) fbp_clean = astra1.reconstruct(sino_clean, 'FBP', n_iterations) sirt_clean = astra1.reconstruct(sino_clean, 'SIRT', n_iterations) print('90 Clean') sino_90 = astra1.sinogram(phant, np.pi/2, n) sino_90 = offset90_v2.centre_sino(sino_90) #graphs.colourmap(sino_90) sino_90 = offset90_v2.mirror_sinogram(sino_90) fbp_90 = astra1.reconstruct(sino_90, 'FBP', n_iterations, np.pi) sirt_90 = astra1.reconstruct(sino_90, 'SIRT', n_iterations, np.pi)