Skip to content

Commit

Permalink
Iterative SIRT working
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigovimieiro committed Feb 4, 2020
1 parent 2c374c1 commit 88e15e7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pydbt/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from functions.initialConfig import initialConfig

from functions.FBP import FDK as FBP
from functions.SIRT import SIRT


#%% Call function for initial configurations
Expand All @@ -36,19 +37,23 @@

#%% Set specific recon parameters

nIter = [2]; # Number of iterations (SIRT)
filterType = 'FBP'; # Filter type: 'BP', 'FBP'
cutoff = 0.75; # Percentage until cut off frequency (FBP)

#%%

print("Starting reconstruction...")

vol = FBP(proj, geo, filterType, cutoff, libFiles)
# ## Uncomment to use ##
# vol = FBP(proj, geo, filterType, cutoff, libFiles)

vol = SIRT(proj, geo, nIter, libFiles)

plt.figure()
plt.title('Reconstructed slice')
plt.imshow(vol[:,:,50] , cmap=plt.get_cmap('gist_gray'))
plt.imsave('output/Reconstructed_slice.tiff',vol[:,:,50] , cmap=plt.get_cmap('gist_gray'))

# print("Starting projection...")
# proj = projectionDDb(vol, geo, libFiles)
Expand Down
59 changes: 59 additions & 0 deletions pydbt/functions/SIRT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 4 07:50:36 2020
@author: Rodrigo
"""

import numpy as np
import time

from functions.backprojectionDDb import backprojectionDDb
from functions.projectionDDb import projectionDDb

def SIRT(proj, geo, nIter, libFiles):

highestValue = (2**16) - 1

# Initial estimated data
reconData3d = np.zeros([geo.ny, geo.nx, geo.nz])

# Pre calculation of Projection normalization
proj_norm = projectionDDb(np.ones([geo.ny, geo.nx, geo.nz]), geo, libFiles)

# Pre calculation of Backprojection normalization
vol_norm = backprojectionDDb(np.ones([geo.nv, geo.nu, geo.nProj]), geo, libFiles)

print('----------------\nStarting SIRT Iterations... \n\n')

# Start Iterations
for iter in range(nIter[-1]):

startTime = time.time()

# Error between raw data and projection of estimated data
proj_diff = proj - projectionDDb(reconData3d, geo, libFiles)

# Projection normalization
proj_diff = proj_diff / proj_norm
proj_diff[np.isnan(proj_diff)] = 0
proj_diff[np.isinf(proj_diff)] = 0

upt_term = backprojectionDDb(proj_diff, geo, libFiles)
upt_term = upt_term / vol_norm # Volume normalization
upt_term[np.isnan(upt_term)] = 0
upt_term[np.isinf(upt_term)] = 0

# Updates the previous estimation
reconData3d = reconData3d + upt_term

endTime = time.time()

# Truncate to highest and minimum value
reconData3d[reconData3d > highestValue] = 0
reconData3d[reconData3d < 0] = 0

print('Itaration %d Time: %.2fs\n\n' % (iter , endTime-startTime))

return reconData3d

0 comments on commit 88e15e7

Please sign in to comment.