Exemplo 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])
Exemplo n.º 2
0
                              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)
                    AnglesVec = angles_rad, # array of angles in radians
Exemplo n.º 3
0
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=
    'LS',  # data fidelity, choose LS, PWLS (wip), GH (wip), Student (wip)
Exemplo n.º 4
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))
#%%
Exemplo n.º 5
0
                                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('TV-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 using ADMM method (tomobar)")
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# Run ADMM reconstrucion algorithm with regularisation
RecADMM_reg = RectoolsIR.ADMM(noisy_zing_stripe,
                              rho_const=5000.0,
                              iterationsADMM=10,
                              regularisation='ROF_TV',
                              regularisation_parameter=0.3)
Exemplo n.º 6
0
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)
plt.title('3D Reconstruction, sagittal view')
Exemplo n.º 7
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))

#%%
Exemplo n.º 8
0
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
    datafidelity=
Exemplo n.º 9
0
                                      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
    CenterRotOffset=None,  # Center of Rotation (CoR) scalar (for 3D case only)
Exemplo n.º 10
0
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)
plt.imshow(RecFISTA_regNLTV, vmin=0, vmax=1, cmap="BuPu")
Exemplo n.º 11
0
                                      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)
    AnglesVec=angles_rad,  # array of angles in radians
Exemplo n.º 12
0
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(
    DetectorsDimH=P,  # Horizontal detector dimension