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')

    graphs.colourmap(sino - offsino)

    # mirror
    offsino = mirror_sinogram(offsino)
    graphs.colourmap(offsino)
    plt.title('Mirrored to 180 degrees')

    # reconstruction
    off_recon = astra1.reconstruct(offsino, 'FBP', 100, np.pi)
    graphs.colourmap(off_recon)
    plt.title('Reconstruction')
"""
    # testing resizing works
    testoff = phantoms.offset_jet(0, 0)
    graphs.colourmap(testoff)
    resized = resize(testoff, 129)

    
    test = phantoms.shockjet(129, 800, 4, 2000, 6)
    graphs.colourmap(resized-test)
    plt.title('Difference')
"""
コード例 #2
0
    # 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)
コード例 #3
0
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]:
        ang_discrepancy_no_noise.append(d)
コード例 #4
0
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)
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)
    #sirt_90 = offset90_v2_29_11.resize(sirt_90, 129)
    
    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
    
    
    graphs.colourmap(sino_diff)
    plt.title('Difference in sinograms.')
    
    # do reconstructions
    reconstruction90 = astra1.reconstruct(sino_mirr,'FBP', 100)
    reconstruction180 = astra1.reconstruct(sinogram180,'FBP', 100)
    
    # difference between reconstruction from 90 degrees and 180 degrees
    reconstruct_diff = reconstruction180 - reconstruction90
    graphs.colourmap(reconstruct_diff)






コード例 #7
0
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)

# image of sinogram
imageio.imwrite('sinogram.png', sinogram_correct_units)

# reconstruction
imageio.imwrite('reconstruction.png', reconstruction)
コード例 #8
0
    for x in range(0,np.shape(stack)[0]-10):
        #graphs.colourmap(corrected_stack[x,0:,0:], equal=False)
        graphs.colourmap(stack[x,0:,0:], equal=False)


        #plt.clim(-4,5)
        #plt.savefig(str(x))
    
    #graphs.colourmap(corrected_stack[0,0:,0:], equal = False)
    #graphs.colourmap(stack[0,0:,0:], equal = False)
    """

    ####### does reconstructions at different heights and plots them & sinos#######
    for x in np.linspace(5, 125, 8, dtype=int):
        #graphs.colourmap(corrected_stack[0:,x,0:], equal=False)
        recon = astra1.reconstruct(corrected_stack[0:, x, 0:], 'SIRT', 100,
                                   np.pi)
        graphs.colourmap(recon)
        plt.title(str(x))

    ####### plots a graph showing how the sinograms are corrected #######

    mean = np.zeros(np.shape(stack[0, 0, 0:]))
    for row in stack[0, 0:, 0:]:
        mean = mean + row
        print(row)
    mean = mean / np.shape(stack[0, 0:, 0:])[1]

    plt.figure()

    x1 = list(range(lower_lim))
    y1 = mean[0:lower_lim]
#n_stack = real_units.num_density(stack)

#smooth_n_stack = improve_data.smooth_sinos(n_stack)
####### does reconstructions at different heights #######
number_of_slices = np.shape(n_stack)[1]
reconstructions = []

for x in np.linspace(0, np.shape(n_stack)[1] - 1, number_of_slices, dtype=int):
    print(x)
    #sino_90 = offset90_v2_29_11.centre_sino(smooth_n_stack[0:90,x,0:])
    #sino_180 = offset90_v2_29_11.mirror_sinogram(sino_90)

    #sino_180 = offset90_v2_29_11.centre_sino(smooth_n_stack[0:180,x,0:])
    sino_180 = offset90_v2_29_11.centre_sino(n_stack[0:180, x, 0:])

    reconstructions.append(astra1.reconstruct(sino_180, 'SIRT', 30, np.pi))

for n in range(len(reconstructions)):
    graphs.colourmap(reconstructions[n])
    #row_num = int((n+1)*np.shape(n_stack)[1]/number_of_slices)
    row_num = int(
        (np.shape(n_stack)[1] - n) * np.shape(n_stack)[1] / number_of_slices)
    plt.title('Row %i' % row_num)
    #plt.clim(0,8E18) # set constant colourmap
    plt.savefig(str(row_num))
    #plt.close()

################ show improvement process:   ##############################
############## as improvement in the sinogram #############################
# choose a height:
height = 120