"""

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)
#    print(int(a/2))
#    s2 = astra1.sinogram(jet, np.pi/2, int(a/2))
#    #graphs.colourmap(s2)
    # 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')

    graphs.colourmap(sino - offsino)

    # mirror
示例#3
0
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)
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
    
    
    graphs.colourmap(sino_diff)
    plt.title('Difference in sinograms.')
    
    # do reconstructions
    reconstruction90 = astra1.reconstruct(sino_mirr,'FBP', 100)
    reconstruction180 = astra1.reconstruct(sinogram180,'FBP', 100)
    
    # calculate relative error as a percentage (relative to phantom)
    rel_err = diff / p * 100
    return np.mean(rel_err) # return the mean so that it can be plotted




# create the original phantom
#phant_centr = phantoms.shockjet(129, 800, 4, 2000, 6) 
phant_centr = phantoms.shockjet(129, 800, 4, 2000, 6) 
#phant_centr2 = phantoms.shockjet(128, 800, 4, 1000, 12) 
#sino_noise = astra1.sinogram(phant_centr, np.pi, 180, gaussian_noise=True, s_and_p_noise=True)
#reconstruction_noise = astra1.reconstruct(sino_noise,'SIRT', 100)


"""
sino_clean = astra1.sinogram(phant_centr, np.pi, 180)
sino_noise = astra1.sinogram(phant_centr, np.pi, 180, gaussian_noise=True, s_and_p_noise=True)



graphs.colourmap(phant_centr)
graphs.colourmap(sino_clean)


graphs.colourmap(sino_noise)


# do reconstruction
reconstruction_clean  = astra1.reconstruct(sino_clean,'SIRT', 100)
reconstruction_noise = astra1.reconstruct(sino_noise,'SIRT', 100)
示例#6
0
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__":

    # 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)
示例#7
0
    for n in range(len(targets)):
        print(target_names[n])
        hybrid_ref = np.zeros(np.shape(targets[n]))
        g = 0
        for sect in range(len(targetdata[n])):
            lhp = targetdata[n][sect][1]
            rhp = targetdata[n][sect][2]
            sect_height = int(1500 / n_fringes)
            best = 1E99
            for m in range(len(refdata)):
                ref = refdata[m]
                dif = abs(ref[sect][1] - lhp) + abs(ref[sect][2] - rhp)
                if dif < best:
                    best = dif
                    best_sect = m

            hybrid_ref[g:g + sect_height, :] = refs[best_sect][g:g +
                                                               sect_height, :]
            g += sect_height
        hybrid_refs.append(hybrid_ref)
    return hybrid_refs


hybr = batch_best_reference(
    r'C:\Users\Elliot Prestidge\Documents\4TH YEAR\Project\Data\6-3-20\1.3mm_refs',
    r'C:\Users\Elliot Prestidge\Documents\4TH YEAR\Project\Data\6-3-20\1.3mm_targs'
)

for r in hybr:
    graphs.colourmap(r)
示例#8
0
        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]
    plt.plot(x1, y1, label='Data used for fit', color='b')
####### 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

sino = stack[0:, height, 0:]
grad_subsino = grad_sub_stack[0:, height, 0:]
for x in range(np.shape(smooth_n_stack)[2]):
    flipped_stack[:, :, -x] = temp_stack[:, :, x]

smooth_n_stack = np.copy(flipped_stack)

lineouts = []
for n in range(len(smooth_n_stack)):
    p = smooth_n_stack[n]
    if sum(p[100, :]) < 0:
        p = -p
        smooth_n_stack[n] = p
    lineouts.append(p[100, :])

frame = 1
for p in smooth_n_stack:
    graphs.colourmap(p)
    #plt.clim(0,9) # set colourmap range
    plt.title('Frame %i' % frame)
    #plt.clim(0,2E18)
    plt.savefig(str(frame))
    frame += 1

#for n in range(len(lineouts)):

plt.figure()
for n in range(6):
    colour = str((len(lineouts) + 0.2) / (n + 0.2))
    plt.plot(range(np.shape(smooth_n_stack)[2]),
             lineouts[n],
             label='Frame:' + str(n))