summaryrefslogtreecommitdiffstats
path: root/python/astra/functions.py
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2018-01-09 15:57:30 +0100
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2018-01-09 15:57:30 +0100
commit8db3ad4cfd4273e9623f5e2824bd3c7e3a71c641 (patch)
tree0a5fd26004481ff68bb3a84d2564e56bec4dff5f /python/astra/functions.py
parentb3393ec49bbe2ffc3eb3b6c7512bb12b8b8d2e52 (diff)
downloadastra-8db3ad4cfd4273e9623f5e2824bd3c7e3a71c641.tar.gz
astra-8db3ad4cfd4273e9623f5e2824bd3c7e3a71c641.tar.bz2
astra-8db3ad4cfd4273e9623f5e2824bd3c7e3a71c641.tar.xz
astra-8db3ad4cfd4273e9623f5e2824bd3c7e3a71c641.zip
Improve postalignment function
Diffstat (limited to 'python/astra/functions.py')
-rw-r--r--python/astra/functions.py32
1 files changed, 13 insertions, 19 deletions
diff --git a/python/astra/functions.py b/python/astra/functions.py
index 5a3d453..0d359b3 100644
--- a/python/astra/functions.py
+++ b/python/astra/functions.py
@@ -280,35 +280,29 @@ def geom_postalignment(proj_geom, factor):
For 2D geometries, the argument factor is a single float specifying the
distance to shift the detector (measured in detector pixels).
- For 3D geometries, factor is a pair of floats specifying the horizontal
- resp. vertical distances to shift the detector.
+ For 3D geometries, factor can be a pair of floats specifying the horizontal
+ resp. vertical distances to shift the detector. If only a single float
+ is specified, this is treated as a horizontal shift.
- :param proj_geom: input projection geometry (vector-based only, use astra.geom_2vec to convert conventional projection geometries)
+ :param proj_geom: input projection geometry
:type proj_geom: :class:`dict`
:param factor: number of pixels to shift the detector
:type factor: :class:`float`
"""
+ proj_geom = geom_2vec(proj_geom)
+
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];
+ V = proj_geom['Vectors']
+ V[:,2:4] = V[:,2:4] + factor * V[:,4:6]
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];
+ V = proj_geom['Vectors']
+ V[:,3:6] = V[:,3:6] + factor[0] * V[:,6:9]
+ if len(factor) > 1:
+ V[:,3:6] = V[:,3:6] + factor[1] * V[:,9:12]
else:
- raise ValueError('No suitable geometry for postalignment: ' + proj_geom['type'])
+ raise RuntimeError('No suitable geometry for postalignment: ' + proj_geom['type'])
return proj_geom