Example #1
0
print("Numerical (ASTRA) sinogram has been generated in {} seconds".format(
    Run_time))

plt.figure()
plt.rcParams.update({'font.size': 21})
plt.imshow(sino_num_ASTRA, cmap="BuPu")
plt.colorbar(ticks=[0, 150, 250], orientation='vertical')
plt.title('{}' '{}'.format('Numerical sinogram (ASTRA) of model no.', model))
#%%
###################################################################
# initialise tomobar reconstruction class ONCE
from tomobar.methodsDIR import RecToolsDIR
RectoolsDIR = RecToolsDIR(
    DetectorsDimH=P,  # DetectorsDimH # detector dimension (horizontal)
    DetectorsDimV=
    None,  # DetectorsDimV # detector dimension (vertical) for 3D case only
    AnglesVec=angles_rad,  # array of angles in radians
    ObjSize=N_size,  # a scalar to define reconstructed object dimensions
    device='cpu')
#%%
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print("Reconstructing analytical sinogram using Fourier Slice method")
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")

RecFourier = RectoolsDIR.fourier(sino_an, 'linear')

plt.figure()
plt.imshow(RecFourier, vmin=0, vmax=1, cmap="BuPu")
plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical')
plt.title('Fourier slice reconstruction')
#%%
Example #2
0
plt.title('2D noisy Projection (analytical)')
plt.subplot(132)
plt.imshow(projData3D_analyt_noisy[sliceSel, :, :], vmin=0, vmax=intens_max)
plt.title('Noisy sinogram view')
plt.subplot(133)
plt.imshow(projData3D_analyt_noisy[:, :, sliceSel], vmin=0, vmax=intens_max)
plt.title('Noisy tangentogram view')
plt.show()
#%%
print("Reconstruction using FBP from tomobar")
# initialise tomobar DIRECT reconstruction class ONCE
from tomobar.methodsDIR import RecToolsDIR
RectoolsDIR = RecToolsDIR(
    DetectorsDimH=Horiz_det,  # DetectorsDimH # detector dimension (horizontal)
    DetectorsDimV=
    Vert_det,  # DetectorsDimV # detector dimension (vertical) for 3D case only
    CenterRotOffset=None,  # Center of Rotation (CoR) scalar (for 3D case only)
    AnglesVec=angles_rad,  # array of angles in radians
    ObjSize=N_size,  # a scalar to define reconstructed object dimensions
    device_projector='gpu')

recNumerical = RectoolsDIR.FBP(projData3D_analyt_noisy)  # FBP reconstruction

sliceSel = int(0.5 * N_size)
max_val = 1
#plt.gray()
plt.figure()
plt.subplot(131)
plt.imshow(recNumerical[sliceSel, :, :], vmin=0, vmax=max_val)
plt.title('3D Reconstruction, axial view')

plt.subplot(132)
Example #3
0
P = int(np.sqrt(2)*N_size) #detectors

sino = TomoP2D.ModelSinoTemporal(model, N_size, P, angles, path_library2D)

plt.figure(2)
plt.rcParams.update({'font.size': 21})
plt.title('{}''{}'.format('2D+t sinogram of model no.',model))
for sl in range(0,np.shape(phantom_2Dt)[0]):
    im = sino[sl,:,:].transpose()
    plt.imshow(im, vmin=0, vmax=180)
    plt.pause(.1)
    plt.draw
#%%
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("Reconstructing analytical sinogram using FBP (tomobar)...")
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# initialise tomobar reconstruction class ONCE
from tomobar.methodsDIR import RecToolsDIR
RectoolsDIR = RecToolsDIR(DetectorsDimH = P,  # DetectorsDimH # detector dimension (horizontal)
                    DetectorsDimV = None,  # DetectorsDimV # detector dimension (vertical) for 3D case only
                    AnglesVec = angles_rad, # array of angles in radians
                    ObjSize = N_size, # a scalar to define reconstructed object dimensions
                    device='cpu')

FBPrec = RectoolsDIR.FBP(sino[15,:,:].transpose()) # reconstruct one frame

plt.figure(3) 
plt.imshow(FBPrec, vmin=0, vmax=1)
plt.title('FBP Reconstructed Phantom')
#%%
Example #4
0
Rectools = RecToolsIR(
    DetectorsDimH=P,  # DetectorsDimH # detector dimension (horizontal)
    DetectorsDimV=
    None,  # DetectorsDimV # detector dimension (vertical) for 3D case only
    CenterRotOffset=None,  # Center of Rotation (CoR) scalar (for 3D case only)
    AnglesVec=angles_rad,  # array of angles in radians
    ObjSize=N_size,  # a scalar to define reconstructed object dimensions
    datafidelity=
    'LS',  # data fidelity, choose LS, PWLS (wip), GH (wip), Student (wip)
    device_projector='gpu')

from tomobar.methodsDIR import RecToolsDIR
RectoolsDIR = RecToolsDIR(
    DetectorsDimH=P,  # DetectorsDimH # detector dimension (horizontal)
    DetectorsDimV=
    None,  # DetectorsDimV # detector dimension (vertical) for 3D case only
    CenterRotOffset=None,  # Center of Rotation (CoR) scalar (for 3D case only)
    AnglesVec=angles_rad,  # array of angles in radians
    ObjSize=N_size,  # a scalar to define reconstructed object dimensions
    device_projector='gpu')

FBPrec = RectoolsDIR.FBP(noisy_sino)  #perform FBP

plt.figure()
plt.imshow(FBPrec, vmin=0, vmax=1, cmap="BuPu")
plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical')
plt.title('FBP reconstruction')

#%%
from ccpi.filters.regularisers import PatchSelect
print("Pre-calculating weights for non-local patches using FBP image...")
plt.ylabel('Projection angle', fontsize=16)
plt.title('Sinogram (X-Y) view', fontsize=19)
plt.subplot(133)
plt.imshow(projdata_norm[:, :, sliceSel], vmin=0, vmax=intens_max, cmap="PuOr")
plt.xlabel('Projection angle', fontsize=16)
plt.ylabel('Z-detector', fontsize=16)
plt.title('Vertical (Y-Z) view', fontsize=19)
plt.show()
#plt.savefig('projdata.pdf', format='pdf', dpi=1200)
#%%
# initialise tomobar DIRECT reconstruction class ONCE
from tomobar.methodsDIR import RecToolsDIR
RectoolsDIR = RecToolsDIR(
    DetectorsDimH=Horiz_det,  # DetectorsDimH # detector dimension (horizontal)
    DetectorsDimV=
    Vert_det,  # DetectorsDimV # detector dimension (vertical) for 3D case only
    AnglesVec=proj_angles,  # array of angles in radians
    ObjSize=N_size,  # a scalar to define reconstructed object dimensions
    device='gpu')
#%%
print("Reconstruction using FBP from tomobar")
recFBP = RectoolsDIR.FBP(projdata_norm)  # FBP reconstruction
#%%
x0, y0 = 0, 127  # These are in _pixel_ coordinates!!
x1, y1 = 255, 127

sliceSel = int(0.5 * N_size)
max_val = 1
plt.figure(figsize=(20, 5))
gs1 = gridspec.GridSpec(1, 3)
gs1.update(wspace=0.1, hspace=0.05)  # set the spacing between axes.
plt.subplot(131)
plt.imshow(projData3D_analyt_noisy[:,sliceSel,:],vmin=0, vmax=intens_max)
plt.title('2D Projection (erroneous)')
plt.subplot(132)
plt.imshow(projData3D_analyt_noisy[sliceSel,:,:],vmin=0, vmax=intens_max)
plt.title('Sinogram view')
plt.subplot(133)
plt.imshow(projData3D_analyt_noisy[:,:,sliceSel],vmin=0, vmax=intens_max)
plt.title('Tangentogram view')
plt.show()
#%%
# initialise tomobar DIRECT reconstruction class ONCE
from tomobar.methodsDIR import RecToolsDIR
RectoolsDIR = RecToolsDIR(DetectorsDimH = Horiz_det,  # Horizontal detector dimension
                    DetectorsDimV = Vert_det,         # Vertical detector dimension (3D case)
                    CenterRotOffset  = None,          # Centre of Rotation scalar
                    AnglesVec = angles_rad,           # A vector of projection angles in radians
                    ObjSize = N_size,                 # Reconstructed object dimensions (scalar)
                    device_projector='gpu')

print ("Reconstruction using FBP from tomobar")
Rec_FBP= RectoolsDIR.FBP(projData3D_analyt_noisy) # FBP reconstruction

sliceSel = int(0.5*N_size)
max_val = 1
#plt.gray()
plt.figure() 
plt.subplot(131)
plt.imshow(Rec_FBP[sliceSel,:,:],vmin=0, vmax=max_val)
plt.title('3D FBP Reconstruction, axial view')

plt.subplot(132)
# adding zingers, stripes and noise
noisy_zing_stripe = _Artifacts_(sinogram = sino_an, \
                                  noise_type='Poisson', noise_sigma=10000, noise_seed = 0, \
                                  zingers_percentage=0.25, zingers_modulus = 10,
                                  stripes_percentage = 1.0, stripes_maxthickness = 1.0)

plt.figure()
plt.rcParams.update({'font.size': 21})
plt.imshow(noisy_zing_stripe,cmap="gray")
plt.colorbar(ticks=[0, 150, 250], orientation='vertical')
plt.title('{}''{}'.format('Analytical noisy sinogram with artifacts.',model))
#%%
from tomobar.methodsDIR import RecToolsDIR
RectoolsDIR = RecToolsDIR(DetectorsDimH = P,  # DetectorsDimH # detector dimension (horizontal)
                    DetectorsDimV = None,  # DetectorsDimV # detector dimension (vertical) for 3D case only
                    CenterRotOffset = None, # Center of Rotation (CoR) scalar (for 3D case only)
                    AnglesVec = angles_rad, # array of angles in radians
                    ObjSize = P, # a scalar to define reconstructed object dimensions
                    device='gpu')

print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("Reconstructing analytical sinogram using FBP (tomobar)...")
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
FBPrec_ideal = RectoolsDIR.FBP(sino_an)  # ideal reconstruction
FBPrec_error = RectoolsDIR.FBP(noisy_zing_stripe) # reconstruction with artifacts
FBPrec_misalign = RectoolsDIR.FBP(noisy_sino_misalign) # reconstruction with misalignment

plt.figure()
plt.subplot(131)
plt.imshow(FBPrec_ideal, vmin=0, vmax=1, cmap="gray")
plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical')
plt.title('Ideal FBP reconstruction')
Example #8
0
plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical')
plt.title('{}'.format('Distorted Phantom'))

#%%
# Generate projection data of distorted phantom

angles_num = int(np.pi * N_size)
# angles number
angles = np.linspace(0.0, 179.9, angles_num, dtype='float32')
angles_rad = angles * (np.pi / 180.0)
P = N_size  #detectors

Rectools = RecToolsDIR(
    DetectorsDimH=P,  # Horizontal detector dimension
    DetectorsDimV=None,  # Vertical detector dimension (3D case)
    CenterRotOffset=0.0,  # Center of Rotation scalar
    AnglesVec=angles_rad,  # A vector of projection angles in radians
    ObjSize=N_size,  # Reconstructed object dimensions (scalar)
    device_projector='gpu')

sino_num = Rectools.FORWPROJ(Object)

_noise_ = {}
_zingers_ = {}
_sinoshifts_ = {}

_stripes_ = {
    'percentage': 0.75,
    'maxthickness': 2.0,
    'intensity': 0.15,
    'type': 'mix',
Example #9
0
plt.subplot(132)
plt.imshow(projData3D_analyt_noise[sliceSel,:,:],vmin=0, vmax=intens_max)
plt.title('Sinogram view')
plt.subplot(133)
plt.imshow(projData3D_analyt_noise[:,:,sliceSel],vmin=0, vmax=intens_max)
plt.title('Tangentogram view')
plt.show()

#%%
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("%%%%%%%%%%%%%%Reconstructing with FBP method %%%%%%%%%%%%%%%")
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
from tomobar.methodsDIR import RecToolsDIR
RectoolsDIR = RecToolsDIR(DetectorsDimH = Horiz_det,     # Horizontal detector dimension
                    DetectorsDimV = Vert_det,            # Vertical detector dimension (3D case)
                    CenterRotOffset = None,              # Center of Rotation scalar or a vector
                    AnglesVec = angles_rad,              # A vector of projection angles in radians
                    ObjSize = N_size,                    # Reconstructed object dimensions (scalar)
                    device_projector='gpu')

FBPrec = RectoolsDIR.FBP(projData3D_analyt_noise) #perform FBP

sliceSel = int(0.5*N_size)
max_val = 1
plt.figure() 
plt.subplot(131)
plt.imshow(FBPrec[sliceSel,:,:],vmin=0, vmax=max_val)
plt.title('3D FBP Reconstruction, axial view')

plt.subplot(132)
plt.imshow(FBPrec[:,sliceSel,:],vmin=0, vmax=max_val)
plt.title('3D FBP Reconstruction, coronal view')