Ejemplo n.º 1
0
    def process_frames(self, data):
        data_temp1 = data[0]
        data_temp2 = data[1]
        indices = np.where(np.isnan(data_temp1))
        data_temp1[indices] = 0.0
        indices = np.where(np.isnan(data_temp2))
        data_temp2[indices] = 0.0

        # collecting values for each slice
        Qtools = QualityTools(data_temp1, data_temp2)
        RMSE = Qtools.rmse()
        print("The Root Mean Square Error is {}".format(RMSE))
        slice_values = [RMSE]
        return np.array([slice_values])
Ejemplo n.º 2
0
                              regularisation_iterations = 100,\
                              lipschitz_const = lc)

plt.figure()
plt.subplot(121)
plt.imshow(RecFISTA, vmin=0, vmax=1, cmap="gray")
plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical')
plt.title('FISTA reconstruction')
plt.subplot(122)
plt.imshow(RecFISTA_reg, vmin=0, vmax=1, cmap="gray")
plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical')
plt.title('Regularised FISTA reconstruction')
plt.show()

# calculate errors 
Qtools = QualityTools(phantom_2D, RecFISTA)
RMSE_FISTA = Qtools.rmse()
Qtools = QualityTools(phantom_2D, RecFISTA_reg)
RMSE_FISTA_reg = Qtools.rmse()
print("RMSE for FISTA is {}".format(RMSE_FISTA))
print("RMSE for regularised FISTA is {}".format(RMSE_FISTA_reg))
#%%
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("Reconstructing with FISTA-OS method")
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
from tomobar.methodsIR import RecToolsIR

# set parameters and initiate a class object
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)
Ejemplo n.º 3
0
plt.figure()
plt.subplot(131)
plt.imshow(recNumerical[sliceSel, :, :], vmin=0, vmax=max_val)
plt.title('3D Reconstruction, axial view')

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

plt.subplot(133)
plt.imshow(recNumerical[:, :, sliceSel], vmin=0, vmax=max_val)
plt.title('3D Reconstruction, sagittal view')
plt.show()

# calculate errors
Qtools = QualityTools(phantom_tm, recNumerical)
RMSE = Qtools.rmse()
print("Root Mean Square Error is {}".format(RMSE))
#%%
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print("Reconstructing with FISTA-OS method using TomoRec")
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# initialise TomoRec ITERATIVE reconstruction class ONCE
from tomorec.methodsIR import RecToolsIR
RectoolsIR = RecToolsIR(
    DetectorsDimH=Horiz_det,  # DetectorsDimH # detector dimension (horizontal)
    DetectorsDimV=
    Vert_det,  # 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
    datafidelity=
Ejemplo n.º 4
0
plt.figure()
plt.subplot(131)
plt.imshow(recNumerical[sliceSel, :, :], vmin=0, vmax=max_val)
plt.title('3D Reconstruction, axial view')

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

plt.subplot(133)
plt.imshow(recNumerical[:, :, sliceSel], vmin=0, vmax=max_val)
plt.title('3D Reconstruction, sagittal view')
plt.show()

# calculate errors
Qtools = QualityTools(Object3D, recNumerical)
RMSE = Qtools.rmse()
print("Root Mean Square Error is {}".format(RMSE))
#%%
"""
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("Reconstructing with FISTA-OS method using tomobar")
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# initialise tomobar ITERATIVE reconstruction class ONCE
from tomobar.methodsIR import RecToolsIR
RectoolsIR = RecToolsIR(DetectorsDimH = Horiz_det,  # DetectorsDimH # detector dimension (horizontal)
                    DetectorsDimV = Vert_det,  # DetectorsDimV # detector dimension (vertical) for 3D case only
                    CenterRotOffset = 0.0, # 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)
Ejemplo n.º 5
0
# Run ADMM reconstrucion algorithm with regularisation
RecADMM_reg = Rectools.ADMM(projData3D_analyt_noise,
                              rho_const = 2000.0, \
                              iterationsADMM = 20, \
                              regularisation = 'FGP_TV', \
                              regularisation_parameter = 0.0035,\
                              regularisation_iterations = 200)


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

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

plt.subplot(133)
plt.imshow(RecADMM_reg[:,:,sliceSel],vmin=0, vmax=max_val)
plt.title('3D ADMM Reconstruction, sagittal view')
plt.show()

# calculate errors 
Qtools = QualityTools(phantom_tm, RecADMM_reg)
RMSE_ADMM = Qtools.rmse()
print("RMSE for regularised ADMM is {}".format(RMSE_ADMM))
#%%
Ejemplo n.º 6
0
plt.figure()
plt.subplot(131)
plt.imshow(recNumerical_conventional[sliceSel, :, :], vmin=0, vmax=max_val)
plt.title('3D Reconstruction, axial view')

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

plt.subplot(133)
plt.imshow(recNumerical_conventional[:, :, sliceSel], vmin=0, vmax=max_val)
plt.title('3D Reconstruction, sagittal view')
plt.show()

# calculate errors
Qtools = QualityTools(phantom_tm, recNumerical_conventional)
RMSE = Qtools.rmse()
print("Root Mean Square Error is {} for conventional flat field normalisation".
      format(RMSE))

plt.figure()
plt.subplot(131)
plt.imshow(recNumerical_dynamic[sliceSel, :, :], vmin=0, vmax=max_val)
plt.title('3D Reconstruction, axial view')

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

plt.subplot(133)
plt.imshow(recNumerical_dynamic[:, :, sliceSel], vmin=0, vmax=max_val)
Ejemplo n.º 7
0
RecFISTA_reg = Rectools.FISTA(_data_, _algorithm_, _regularisation_)

plt.figure()
plt.subplot(121)
plt.imshow(RecFISTA, vmin=0, vmax=1, cmap="gray")
plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical')
plt.title('FISTA reconstruction')
plt.subplot(122)
plt.imshow(RecFISTA_reg, vmin=0, vmax=1, cmap="gray")
plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical')
plt.title('Regularised FISTA reconstruction')
plt.show()

# calculate errors
Qtools = QualityTools(phantom_2D[indicesROI], RecFISTA[indicesROI])
RMSE_FISTA = Qtools.rmse()
Qtools = QualityTools(phantom_2D[indicesROI], RecFISTA_reg[indicesROI])
RMSE_FISTA_reg = Qtools.rmse()
print("RMSE for FISTA is {}".format(RMSE_FISTA))
print("RMSE for regularised FISTA is {}".format(RMSE_FISTA_reg))
#%%
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print("Reconstructing with FISTA-OS method")
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
from tomobar.methodsIR import RecToolsIR

# set parameters and initiate a class object
Rectools = RecToolsIR(
    DetectorsDimH=P,  # Horizontal detector dimension
    DetectorsDimV=None,  # Vertical detector dimension (3D case)
Ejemplo n.º 8
0
print("Reconstructing analytical sinogram using FBP (astra TB)...")
FBPrec1 = RectoolsDIR.FBP(sino_an)
plt.figure()
plt.imshow(FBPrec1, vmin=0, vmax=1, cmap="BuPu")
plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical')
plt.title('FBP Reconstructed Phantom (analyt)')

print("Reconstructing numerical sinogram using FBP (astra TB)...")
FBPrec2 = RectoolsDIR.FBP(sino_num_ASTRA)

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

plt.figure()
plt.imshow(abs(FBPrec1 - FBPrec2), vmin=0, vmax=0.05, cmap="BuPu")
plt.colorbar(ticks=[0, 0.02, 0.05], orientation='vertical')
plt.title('FBP rec differences')
# rmse2 = np.linalg.norm(FBPrec1 - FBPrec2)/np.linalg.norm(FBPrec2)

Qtools = QualityTools(phantom_2D, FBPrec1)
RMSE_FBP1 = Qtools.rmse()
Qtools = QualityTools(phantom_2D, FBPrec2)
RMSE_FBP2 = Qtools.rmse()
print("RMSE for FBP (analyt) {}".format(RMSE_FBP1))
print("RMSE for FBP (numeric) {}".format(RMSE_FBP2))

#%%
Ejemplo n.º 9
0
plt.figure()
plt.subplot(131)
plt.imshow(recNumerical[sliceSel, :, :], vmin=0, vmax=max_val)
plt.title('3D Reconstruction, axial view')

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

plt.subplot(133)
plt.imshow(recNumerical[:, :, sliceSel], vmin=0, vmax=max_val)
plt.title('3D Reconstruction, sagittal view')
plt.show()

# calculate errors
Qtools = QualityTools(phantom_tm, recNumerical)
RMSE = Qtools.rmse()
print("Root Mean Square Error is {}".format(RMSE))
#%%
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print("Reconstructing with FISTA-OS method using tomobar")
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# initialise tomobar ITERATIVE reconstruction class ONCE
from tomobar.methodsIR import RecToolsIR
Rectools = RecToolsIR(
    DetectorsDimH=Horiz_det,  # DetectorsDimH # detector dimension (horizontal)
    DetectorsDimV=
    Vert_det,  # DetectorsDimV # detector dimension (vertical) for 3D case only
    CenterRotOffset=0.0,  # 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
Ejemplo n.º 10
0
                                      regularisation_parameter=0.003,
                                      lipschitz_const=lc)

plt.figure()
plt.subplot(121)
plt.imshow(RecFISTA_LS_reg, vmin=0, vmax=1, cmap="gray")
plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical')
plt.title('FISTA-LS-TV reconstruction')
plt.subplot(122)
plt.imshow(RecFISTA_Huber_reg, vmin=0, vmax=1, cmap="gray")
plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical')
plt.title('FISTA-Huber-TV reconstruction')
plt.show()

# calculate errors
Qtools = QualityTools(phantom_2D, RecFISTA_LS_reg)
RMSE_FISTA_LS_TV = Qtools.rmse()
Qtools = QualityTools(phantom_2D, RecFISTA_Huber_reg)
RMSE_FISTA_HUBER_TV = Qtools.rmse()
print("RMSE for FISTA-LS-TV reconstruction is {}".format(RMSE_FISTA_LS_TV))
print("RMSE for FISTA-Huber-TV is {}".format(RMSE_FISTA_HUBER_TV))
#%%
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print("Reconstructing using FISTA-OS method (tomobar)")
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")

from tomobar.methodsIR import RecToolsIR
RectoolsIR = RecToolsIR(
    DetectorsDimH=P,  # DetectorsDimH # detector dimension (horizontal)
    DetectorsDimV=
    None,  # DetectorsDimV # detector dimension (vertical) for 3D case only
Ejemplo n.º 11
0
tic = timeit.default_timer()
print("Run FISTA reconstrucion algorithm with NLTV regularisation...")
RecFISTA_regNLTV = Rectools.FISTA(noisy_sino, iterationsFISTA = 250, \
                              regularisation = 'NLTV', \
                              regularisation_parameter = 0.002,\
                              regularisation_iterations = 3,\
                              NLTV_H_i = H_i,\
                              NLTV_H_j = H_j,\
                              NLTV_Weights = Weights,\
                              lipschitz_const = lc)
toc = timeit.default_timer()
Run_time = toc - tic
print("FISTA-NLTV completed in {} seconds".format(Run_time))

# calculate errors
Qtools = QualityTools(phantom_2D, RecFISTA_regTV)
RMSE_FISTA_TV = Qtools.rmse()
Qtools = QualityTools(phantom_2D, RecFISTA_regNLTV)
RMSE_FISTA_NLTV = Qtools.rmse()
print("RMSE for TV-regularised FISTA is {}".format(RMSE_FISTA_TV))
print("RMSE for NLTV-regularised FISTA is {}".format(RMSE_FISTA_NLTV))

plt.figure()
plt.subplot(121)
plt.imshow(RecFISTA_regTV, vmin=0, vmax=1, cmap="BuPu")
plt.text(0.0, 550, 'RMSE is %s\n' % (round(RMSE_FISTA_TV, 3)), {
    'color': 'b',
    'fontsize': 20
})
plt.title('TV Regularised FISTA reconstruction')
plt.subplot(122)
Ejemplo n.º 12
0
    'method': 'PD_TV',
    'regul_param': 0.1,
    'iterations': 150,
    'device_regulariser': 'gpu'
}

RecADMM_reg = RectoolsIR.ADMM(_data_, _algorithm_, _regularisation_)

plt.figure()
plt.imshow(RecADMM_reg, vmin=0, vmax=2, cmap="gray")
plt.colorbar(ticks=[0, 0.5, 3], orientation='vertical')
plt.title('ADMM reconstruction')
plt.show()

# calculate errors
Qtools = QualityTools(phantom_2D, RecADMM_reg)
RMSE_ADMM_reg = Qtools.rmse()
print("RMSE for regularised ADMM is {}".format(RMSE_ADMM_reg))
#%%
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print("Reconstructing using FISTA method (tomobar)")
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# prepare dictionaries with parameters:
_data_ = {
    'projection_norm_data': noisy_zing_stripe,
    'huber_threshold': 4.5,
    'ring_weights_threshold': 10.0,
    'ring_tuple_halfsizes': (9, 5, 0)
}  # data dictionary

lc = RectoolsIR.powermethod(
Ejemplo n.º 13
0
                                      regularisation_parameter=0.003,
                                      lipschitz_const=lc)

plt.figure()
plt.subplot(121)
plt.imshow(RecFISTA_LS_reg, vmin=0, vmax=3, cmap="gray")
plt.colorbar(ticks=[0, 0.5, 3], orientation='vertical')
plt.title('FISTA-LS-TV reconstruction')
plt.subplot(122)
plt.imshow(RecFISTA_Huber_reg, vmin=0, vmax=3, cmap="gray")
plt.colorbar(ticks=[0, 0.5, 3], orientation='vertical')
plt.title('FISTA-Huber-TV reconstruction')
plt.show()

# calculate errors
Qtools = QualityTools(phantom_2D, RecFISTA_LS_reg)
RMSE_FISTA_LS_TV = Qtools.rmse()
Qtools = QualityTools(phantom_2D, RecFISTA_Huber_reg)
RMSE_FISTA_HUBER_TV = Qtools.rmse()
print("RMSE for FISTA-LS-TV reconstruction is {}".format(RMSE_FISTA_LS_TV))
print("RMSE for FISTA-Huber-TV is {}".format(RMSE_FISTA_HUBER_TV))
#%%
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print("Reconstructing using FISTA-OS method (tomobar)")
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
from tomobar.methodsIR import RecToolsIR
RectoolsIR = 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)
Ejemplo n.º 14
0
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)
plt.imshow(Rec_FBP[:,sliceSel,:],vmin=0, vmax=max_val)
plt.title('3D FBP Reconstruction, coronal view')

plt.subplot(133)
plt.imshow(Rec_FBP[:,:,sliceSel],vmin=0, vmax=max_val)
plt.title('3D FBP Reconstruction, sagittal view')
plt.show()

# calculate errors 
Qtools = QualityTools(phantom_tm, Rec_FBP)
RMSE = Qtools.rmse()
print("Root Mean Square Error is {}".format(RMSE))
#%%
# Reconstructing misaligned data using exact shifts

# 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  = -shifts2D,     # 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")
Ejemplo n.º 15
0
plt.subplot(131)
plt.imshow(RecFISTA_LS_reg, vmin=0, vmax=maxval, cmap="gray")
plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical')
plt.title('FISTA-PWLS-TV reconstruction')
plt.subplot(132)
plt.imshow(RecFISTA_Huber_reg, vmin=0, vmax=maxval, cmap="gray")
plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical')
plt.title('FISTA-Huber-TV reconstruction')
plt.subplot(133)
plt.imshow(RecFISTA_HuberRing_reg, vmin=0, vmax=maxval, cmap="gray")
plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical')
plt.title('FISTA-HuberRing-TV reconstruction')
plt.show()

# calculate errors
Qtools = QualityTools(phantom_2D[indicesROI], RecFISTA_LS_reg[indicesROI])
RMSE_FISTA_LS_TV = Qtools.rmse()
Qtools = QualityTools(phantom_2D[indicesROI], RecFISTA_Huber_reg[indicesROI])
RMSE_FISTA_HUBER_TV = Qtools.rmse()
Qtools = QualityTools(phantom_2D[indicesROI],
                      RecFISTA_HuberRing_reg[indicesROI])
RMSE_FISTA_HUBERRING_TV = Qtools.rmse()
print("RMSE for FISTA-PWLS-TV reconstruction is {}".format(RMSE_FISTA_LS_TV))
print("RMSE for FISTA-Huber-TV is {}".format(RMSE_FISTA_HUBER_TV))
print("RMSE for FISTA-OS-HuberRing-TV is {}".format(RMSE_FISTA_HUBERRING_TV))
#%%
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print("Reconstructing using FISTA-OS-SWLS method (tomobar)")
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
from tomobar.methodsIR import RecToolsIR
RectoolsIR = RecToolsIR(