summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Python/ccpi/reconstruction/AstraDevice.py24
-rw-r--r--src/Python/ccpi/reconstruction/FISTAReconstructor.py52
-rw-r--r--src/Python/test/test_reconstructor-os.py2
3 files changed, 56 insertions, 22 deletions
diff --git a/src/Python/ccpi/reconstruction/AstraDevice.py b/src/Python/ccpi/reconstruction/AstraDevice.py
index ac9206e..61e95ce 100644
--- a/src/Python/ccpi/reconstruction/AstraDevice.py
+++ b/src/Python/ccpi/reconstruction/AstraDevice.py
@@ -41,7 +41,7 @@ Uses Astra-toolbox
volume, self.proj_geom, self.vol_geom)
astra.matlab.data3d('delete', sino_id)
return y
- except Exception(e):
+ except Exception as e:
print(e)
print("Value Error: ", self.proj_geom, self.vol_geom)
@@ -59,19 +59,33 @@ Uses Astra-toolbox
astra.matlab.data3d('delete', idx)
return volume
- def createReducedDevice(self):
+ def createReducedDevice(self, proj_par={'cameraY' : 1} , vol_par={'Z':1}):
+ '''Change the definition of the current device by changing some parameter
+
+VERY RISKY'''
+ for k,v in proj_par.items():
+ if k in self.acquisition_data_geometry.keys():
+ print ("Reduced device updating " , k , v)
+ self.acquisition_data_geometry[k] = v
+ print ("Reduced Device: ", self.acquisition_data_geometry)
proj_geom = [
self.acquisition_data_geometry['cameraX'],
- 1,
+ self.acquisition_data_geometry['cameraY'],
self.acquisition_data_geometry['detectorSpacingX'],
self.acquisition_data_geometry['detectorSpacingY'],
self.acquisition_data_geometry['angles']
]
-
+
+ for k,v in vol_par.items():
+ if k in self.reconstructed_volume_geometry.keys():
+ print ("Reduced device updating " , k , v)
+ self.reconstructed_volume_geometry[k] = v
+ print ("Reduced Device: ",self.reconstructed_volume_geometry)
+
vol_geom = [
self.reconstructed_volume_geometry['X'],
self.reconstructed_volume_geometry['Y'],
- 1
+ self.reconstructed_volume_geometry['Z']
]
return AstraDevice(self.type, proj_geom, vol_geom)
diff --git a/src/Python/ccpi/reconstruction/FISTAReconstructor.py b/src/Python/ccpi/reconstruction/FISTAReconstructor.py
index b549755..3c576c4 100644
--- a/src/Python/ccpi/reconstruction/FISTAReconstructor.py
+++ b/src/Python/ccpi/reconstruction/FISTAReconstructor.py
@@ -664,7 +664,7 @@ class FISTAReconstructor():
'ring_lambda_R_L1', 'Lipschitz_constant',
'number_of_iterations'])
-
+
# errors vector (if the ground truth is given)
Resid_error = numpy.zeros((iterFISTA));
# objective function values vector
@@ -727,7 +727,12 @@ class FISTAReconstructor():
for j in range(len(CurrSubIndices)):
mask[int(CurrSubIndices[j])] = True
proj_geomSUB['ProjectionAngles'] = angles[mask]
-
+ if self.use_device:
+ device = self.getParameter('device_model')\
+ .createReducedDevice(
+ proj_par={'angles':angles[mask]},
+ vol_par={})
+
shape = list(numpy.shape(self.getParameter('input_sinogram')))
shape[1] = numProjSub
sino_updt_Sub = numpy.zeros(shape)
@@ -736,17 +741,24 @@ class FISTAReconstructor():
geometry_type == 'fanflat_vec' :
for kkk in range(SlicesZ):
- sino_id, sinoT = astra.creators.create_sino3d_gpu (
- X_t[kkk:kkk+1] , proj_geomSUB, vol_geom)
- sino_updt_Sub[kkk] = sinoT.T.copy()
+ if self.use_device:
+ sinoT = device.doForwardProject(X_t[kkk:kkk+1])
+ else:
+ sino_id, sinoT = astra.creators.create_sino3d_gpu (
+ X_t[kkk:kkk+1] , proj_geomSUB, vol_geom)
+ sino_updt_Sub[kkk] = sinoT.T.copy()
+ astra.matlab.data3d('delete', sino_id)
else:
# for 3D geometry (watch the GPU memory overflow in
# ASTRA < 1.8)
- sino_id, sino_updt_Sub = \
- astra.creators.create_sino3d_gpu (X_t, proj_geomSUB, vol_geom)
-
- astra.matlab.data3d('delete', sino_id)
+ if self.use_device:
+ sino_updt_Sub = device.doForwardProject(X_t)
+ else:
+ sino_id, sino_updt_Sub = \
+ astra.creators.create_sino3d_gpu (X_t, proj_geomSUB, vol_geom)
+
+ astra.matlab.data3d('delete', sino_id)
if lambdaR_L1 > 0 :
@@ -773,18 +785,26 @@ class FISTAReconstructor():
# routine
x_temp = numpy.zeros(numpy.shape(X), dtype=numpy.float32)
for kkk in range(SlicesZ):
-
- x_id, x_temp[kkk] = \
- astra.creators.create_backprojection3d_gpu(
- residualSub[kkk:kkk+1],
- proj_geomSUB, vol_geom)
+ if self.use_device:
+ x_temp[kkk] = device.doBackwardProject(
+ residualSub[kkk:kkk+1])
+ else:
+ x_id, x_temp[kkk] = \
+ astra.creators.create_backprojection3d_gpu(
+ residualSub[kkk:kkk+1],
+ proj_geomSUB, vol_geom)
+ astra.matlab.data3d('delete', x_id)
else:
- x_id, x_temp = \
+ if self.use_device:
+ x_temp = device.doBackwardProject(
+ residualSub)
+ else:
+ x_id, x_temp = \
astra.creators.create_backprojection3d_gpu(
residualSub, proj_geomSUB, vol_geom)
- astra.matlab.data3d('delete', x_id)
+ astra.matlab.data3d('delete', x_id)
X = X_t - (1/L_const) * x_temp
## REGULARIZATION
X = self.regularize(X)
diff --git a/src/Python/test/test_reconstructor-os.py b/src/Python/test/test_reconstructor-os.py
index 78b24a3..21b7ecd 100644
--- a/src/Python/test/test_reconstructor-os.py
+++ b/src/Python/test/test_reconstructor-os.py
@@ -390,7 +390,7 @@ else:
subsets=8)
print ("Lipschitz Constant {0}".format(fistaRecon.pars['Lipschitz_constant']))
- fistaRecon.setParameter(number_of_iterations = 12)
+ fistaRecon.setParameter(number_of_iterations = 2)
fistaRecon.setParameter(Lipschitz_constant = 767893952.0)
fistaRecon.setParameter(ring_alpha = 21)
fistaRecon.setParameter(ring_lambda_R_L1 = 0.002)