summaryrefslogtreecommitdiffstats
path: root/python/astra
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2018-01-09 14:09:40 +0100
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2018-01-09 14:09:40 +0100
commitde27e439a0c59fade175fba4e0b4a1e0c84b933d (patch)
tree8d724e10b35291f5bfd63174eeeca95e52a863df /python/astra
parent324611ce98a82944def875e61cb93dd98ced9c79 (diff)
parent84da1d5e27abadf28e97695e88494c58bf1c2697 (diff)
downloadastra-de27e439a0c59fade175fba4e0b4a1e0c84b933d.tar.gz
astra-de27e439a0c59fade175fba4e0b4a1e0c84b933d.tar.bz2
astra-de27e439a0c59fade175fba4e0b4a1e0c84b933d.tar.xz
astra-de27e439a0c59fade175fba4e0b4a1e0c84b933d.zip
Merge branch 'parallel_vec'
Diffstat (limited to 'python/astra')
-rw-r--r--python/astra/PyIncludes.pxd4
-rw-r--r--python/astra/creators.py13
-rw-r--r--python/astra/data2d_c.pyx4
-rw-r--r--python/astra/functions.py56
-rw-r--r--python/astra/pythonutils.py2
5 files changed, 77 insertions, 2 deletions
diff --git a/python/astra/PyIncludes.pxd b/python/astra/PyIncludes.pxd
index ec37d0a..84469aa 100644
--- a/python/astra/PyIncludes.pxd
+++ b/python/astra/PyIncludes.pxd
@@ -128,6 +128,10 @@ cdef extern from "astra/FanFlatVecProjectionGeometry2D.h" namespace "astra":
cdef cppclass CFanFlatVecProjectionGeometry2D:
CFanFlatVecProjectionGeometry2D()
+cdef extern from "astra/ParallelVecProjectionGeometry2D.h" namespace "astra":
+ cdef cppclass CParallelVecProjectionGeometry2D:
+ CParallelVecProjectionGeometry2D()
+
cdef extern from "astra/ParallelProjectionGeometry2D.h" namespace "astra":
cdef cppclass CParallelProjectionGeometry2D:
CParallelProjectionGeometry2D()
diff --git a/python/astra/creators.py b/python/astra/creators.py
index 1e4d937..85daf82 100644
--- a/python/astra/creators.py
+++ b/python/astra/creators.py
@@ -147,6 +147,13 @@ This method can be called in a number of ways:
:type angles: :class:`numpy.ndarray`
:returns: A parallel projection geometry.
+``create_proj_geom('parallel_vec', det_count, V)``:
+
+:param det_count: Number of detector pixels.
+:type det_count: :class:`int`
+:param V: Vector array.
+:type V: :class:`numpy.ndarray`
+:returns: A parallel-beam projection geometry.
``create_proj_geom('fanflat', det_width, det_count, angles, source_origin, origin_det)``:
@@ -234,6 +241,12 @@ This method can be called in a number of ways:
raise Exception(
'not enough variables: astra_create_proj_geom(parallel, detector_spacing, det_count, angles)')
return {'type': 'parallel', 'DetectorWidth': args[0], 'DetectorCount': args[1], 'ProjectionAngles': args[2]}
+ elif intype == 'parallel_vec':
+ if len(args) < 2:
+ raise Exception('not enough variables: astra_create_proj_geom(parallel_vec, det_count, V)')
+ if not args[1].shape[1] == 6:
+ raise Exception('V should be a Nx6 matrix, with N the number of projections')
+ return {'type':'parallel_vec', 'DetectorCount':args[0], 'Vectors':args[1]}
elif intype == 'fanflat':
if len(args) < 5:
raise Exception('not enough variables: astra_create_proj_geom(fanflat, det_width, det_count, angles, source_origin, origin_det)')
diff --git a/python/astra/data2d_c.pyx b/python/astra/data2d_c.pyx
index 9c88073..1b1125d 100644
--- a/python/astra/data2d_c.pyx
+++ b/python/astra/data2d_c.pyx
@@ -111,6 +111,8 @@ def create(datatype, geometry, data=None, link=False):
ppGeometry = <CProjectionGeometry2D * >new CFanFlatProjectionGeometry2D()
elif (tpe == 'fanflat_vec'):
ppGeometry = <CProjectionGeometry2D * >new CFanFlatVecProjectionGeometry2D()
+ elif (tpe == 'parallel_vec'):
+ ppGeometry = <CProjectionGeometry2D * >new CParallelVecProjectionGeometry2D()
else:
ppGeometry = <CProjectionGeometry2D * >new CParallelProjectionGeometry2D()
if not ppGeometry.initialize(cfg[0]):
@@ -225,6 +227,8 @@ def change_geometry(i, geom):
ppGeometry = <CProjectionGeometry2D * >new CFanFlatProjectionGeometry2D()
elif (tpe == 'fanflat_vec'):
ppGeometry = <CProjectionGeometry2D * >new CFanFlatVecProjectionGeometry2D()
+ elif (tpe == 'parallel_vec'):
+ ppGeometry = <CProjectionGeometry2D * >new CParallelVecProjectionGeometry2D()
else:
ppGeometry = <CProjectionGeometry2D * >new CParallelProjectionGeometry2D()
if not ppGeometry.initialize(cfg[0]):
diff --git a/python/astra/functions.py b/python/astra/functions.py
index 7277de5..b3a470d 100644
--- a/python/astra/functions.py
+++ b/python/astra/functions.py
@@ -172,7 +172,27 @@ def geom_2vec(proj_geom):
:param proj_geom: Projection geometry to convert
:type proj_geom: :class:`dict`
"""
- if proj_geom['type'] == 'fanflat':
+
+ if proj_geom['type'] == 'parallel':
+ angles = proj_geom['ProjectionAngles']
+ vectors = np.zeros((len(angles), 6))
+ for i in range(len(angles)):
+
+ # source
+ vectors[i, 0] = np.sin(angles[i])
+ vectors[i, 1] = -np.cos(angles[i])
+
+ # center of detector
+ vectors[i, 2] = 0
+ vectors[i, 3] = 0
+
+ # vector from detector pixel 0 to 1
+ vectors[i, 4] = np.cos(angles[i]) * proj_geom['DetectorWidth']
+ vectors[i, 5] = np.sin(angles[i]) * proj_geom['DetectorWidth']
+ proj_geom_out = ac.create_proj_geom(
+ 'parallel_vec', proj_geom['DetectorCount'], vectors)
+
+ elif proj_geom['type'] == 'fanflat':
angles = proj_geom['ProjectionAngles']
vectors = np.zeros((len(angles), 6))
for i in range(len(angles)):
@@ -251,3 +271,37 @@ def geom_2vec(proj_geom):
raise ValueError(
'No suitable vector geometry found for type: ' + proj_geom['type'])
return proj_geom_out
+
+
+def geom_postalignment(proj_geom, factor):
+ """Returns the size of a volume or sinogram, based on the projection or volume geometry.
+
+ :param proj_geom: input projection geometry (vector-based only, use astra.geom_2vec to convert conventional projection geometries)
+ :type proj_geom: :class:`dict`
+ :param factor: Optional axis index to return
+ :type factor: :class:`float`
+ """
+
+ if proj_geom['type'] == 'parallel_vec' or proj_geom['type'] == 'fanflat_vec':
+ for i in range(proj_geom['Vectors'].shape[0]):
+ proj_geom['Vectors'][i,2] = proj_geom['Vectors'][i,2] + factor * proj_geom['Vectors'][i,4];
+ proj_geom['Vectors'][i,3] = proj_geom['Vectors'][i,3] + factor * proj_geom['Vectors'][i,5];
+
+ elif proj_geom['type'] == 'parallel3d_vec' or proj_geom['type'] == 'cone_vec':
+
+ if len(factor) == 1:
+ for i in range(proj_geom['Vectors'].shape[0]):
+ proj_geom['Vectors'][i,3] = proj_geom['Vectors'][i,3] + factor * proj_geom['Vectors'][i,6];
+ proj_geom['Vectors'][i,4] = proj_geom['Vectors'][i,4] + factor * proj_geom['Vectors'][i,7];
+ proj_geom['Vectors'][i,5] = proj_geom['Vectors'][i,5] + factor * proj_geom['Vectors'][i,8];
+
+ elif len(factor) > 1:
+ for i in range(proj_geom['Vectors'].shape[0]):
+ proj_geom['Vectors'][i,3] = proj_geom['Vectors'][i,3] + factor[0] * proj_geom['Vectors'][i,6] + factor[1] * proj_geom['Vectors'][i, 9];
+ proj_geom['Vectors'][i,4] = proj_geom['Vectors'][i,4] + factor[0] * proj_geom['Vectors'][i,7] + factor[1] * proj_geom['Vectors'][i,10];
+ proj_geom['Vectors'][i,5] = proj_geom['Vectors'][i,5] + factor[0] * proj_geom['Vectors'][i,8] + factor[1] * proj_geom['Vectors'][i,11];
+ else:
+ raise ValueError('No suitable geometry for postalignment: ' + proj_geom['type'])
+
+ return proj_geom
+
diff --git a/python/astra/pythonutils.py b/python/astra/pythonutils.py
index 27fa8fd..1028a0a 100644
--- a/python/astra/pythonutils.py
+++ b/python/astra/pythonutils.py
@@ -51,7 +51,7 @@ def geom_size(geom, dim=None):
elif geom['type'] == 'parallel3d' or geom['type'] == 'cone':
s = (geom['DetectorRowCount'], len(
geom['ProjectionAngles']), geom['DetectorColCount'])
- elif geom['type'] == 'fanflat_vec':
+ elif geom['type'] == 'fanflat_vec' or geom['type'] == 'parallel_vec':
s = (geom['Vectors'].shape[0], geom['DetectorCount'])
elif geom['type'] == 'parallel3d_vec' or geom['type'] == 'cone_vec':
s = (geom['DetectorRowCount'], geom[