Skip to content

Commit 746a049

Browse files
committed
Merge branch 'astra-integration'
2 parents b435ea4 + f628bab commit 746a049

File tree

121 files changed

+6818
-94
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+6818
-94
lines changed

.gitignore/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ docs/_templates/
1111

1212
# Various IDE folders
1313
.idea
14-
.vscode
14+
.vscode
15+
16+
# Astra source files
17+
src/astra

docs/images/Cone_beam.jpg

307 KB
Loading

docs/images/Figures.ai

Lines changed: 1829 additions & 0 deletions
Large diffs are not rendered by default.

docs/images/Laminography_parallel.jpg

352 KB
Loading

docs/imageset.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Image set creation
99
Constructor for the :class:`CALCreateImageSet` class that creates an image set given a :class:`ProjObj` and structure of image transformation parameters.
1010

1111

12+
1213
:Parameters: * projection_obj - :class:`ProjObj` containing the projections OR a "plain" 3D projection matrix (FOR BACKWARD COMPATIBILITY)
1314

1415
* image_params - structure of image transformation parameters (refer to image at the end of this section for visual depiction of some of the parameters)

docs/projectors.rst

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,26 @@ Constructor
3636
:Parameters: * target_obj - :class:`TargetObj` containing the target (output from :func:`CALPrepTarget`)
3737
* proj_params - structure of projection parameters defining the projection configuration
3838
* proj_params.angles - vector of angles at which to perform forward and back projection
39+
* proj_params.CUDA - en/disables usage of Astra toolbox GPU accelerated projector
40+
* proj_params.inclination_angle - angle of elevation from normal tomographic plane
41+
* proj_params.cone_angle - angle of maximum ray divergence along rotation axis in cone beam geometry
3942
* parallel - whether or not to use parallel processing when performing forward and back projection
4043

4144
:Returns: * ProjectorObj - :class:`ProjectorObj` that links to the correct projector depending on the target dimensions
4245

43-
3D
44-
--
46+
3D (Matlab)
47+
-----------
4548

46-
.. class:: Projector3D(proj_params,parallel)
49+
.. class:: Projector3DParallel(proj_params,parallel)
4750

48-
Constructs a :class:`Projector3D` object for performing 3D forward and back projection.
51+
Constructs a :class:`Projector3DParallel` object for performing 3D forward and back projection with **parallel ray geometry** using Matlab's ``radon`` and ``iradon`` functions.
4952

5053

5154
:Parameters: * proj_params - structure of projection parameters defining the projection configuration
5255
* proj_params.angles - vector of angles at which to perform forward and back projection
5356
* parallel - whether or not to use parallel processing when performing forward and back projection
5457

55-
:Returns: * obj - :class:`Projector3D`
58+
:Returns: * obj - :class:`Projector3DParallel`
5659

5760
.. classmethod:: forward(x)
5861

@@ -70,19 +73,50 @@ Constructor
7073

7174
:Returns: * x - 3D matrix of reconstruction. Dimensions will be ``[nT,nT,nZ]`` where ``nT`` is the number of elements in the transverse/radial direction and ``nZ`` is the number of z-slices
7275

73-
2D
74-
--
76+
3D (Astra)
77+
----------
78+
.. class:: Projector3DCUDA(proj_params)
79+
80+
Constructs a :class:`Projector3DCUDA` object for performing 3D forward and back projection with **parallel and cone beam geometry** using Astra Toolbox GPU accelerated projectors.
81+
82+
83+
:Parameters: * proj_params - structure of projection parameters defining the projection configuration
84+
* proj_params.angles - vector of angles at which to perform forward and back projection
85+
* proj_params.CUDA - en/disables usage of Astra toolbox GPU accelerated projector
86+
* proj_params.inclination_angle - angle of elevation from normal tomographic plane
87+
* proj_params.cone_angle - angle of maximum ray divergence along rotation axis in cone beam geometry
88+
89+
90+
:Returns: * obj - :class:`Projector3DCUDA`
91+
92+
.. classmethod:: forward(x)
93+
94+
Performs 3D forward projection using Astra's GPU accelerated 3D projectors.
7595

96+
:Parameters: * x - 3D matrix of target
97+
98+
:Returns: * b - 3D matrix of sinograms. Dimensions will be ``[nT,nTheta,nZ]`` where ``nT`` is the number of elements in the transverse/radial direction, ``nTheta`` is the number of angles, and ``nZ`` is the number of z-slices
99+
100+
.. classmethod:: backward(b)
101+
102+
Performs 3D back projection using Astra's GPU accelerated 3D projectors.
103+
104+
:Parameters: * b - 3D matrix of sinograms
105+
106+
:Returns: * x - 3D matrix of reconstruction. Dimensions will be ``[nT,nT,nZ]`` where ``nT`` is the number of elements in the transverse/radial direction and ``nZ`` is the number of z-slices
107+
108+
2D (Matlab)
109+
-----------
76110

77-
.. class:: Projector2D(proj_params)
111+
.. class:: Projector2DParallel(proj_params)
78112

79-
Constructs a :class:`Projector2D` object for performing 2D forward and back projection.
113+
Constructs a :class:`Projector2DParallel` object for performing 2D forward and back projection with **parallel beam geometry** using Matlab's :func:`radon` and :func:`iradon` functions.
80114

81115

82116
:Parameters: * proj_params - structure of projection parameters defining the projection configuration
83117
* proj_params.angles - vector of angles at which to perform forward and back projection
84118

85-
:Returns: * obj - :class:`Projector2D`
119+
:Returns: * obj - :class:`Projector2DParallel`
86120

87121
.. classmethod:: forward(x)
88122

docs/sec_setup.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,29 @@ The `CAL-software-Matlab`_ package can be installed by completing the following
2727
::
2828
CALtest()
2929

30-
You should see the following if the installation succeeded:
30+
This function will test the basic functionality of the toolbox and check if a GPU is available for the use of the `Astra toolbox`_ which is included in this toolbox.
31+
32+
You should see the following if installation was successful:
3133
::
3234
CAL-software-Matlab Toolbox installed successfully!
35+
Getting GPU info...
36+
Testing basic CPU 2D functionality...
37+
Testing basic CUDA 2D functionality...
38+
Testing basic CUDA 3D functionality...
39+
40+
If your computer has a NVIDIA GPU the CUDA 2D and 3D functionality should say "Ok".
3341

3442
Now the toolbox can be used like any other Matlab toolbox. You do not need to be in a particular working directory to access the functions of the toolbox.
3543

44+
45+
Astra Toolbox
46+
-------------
47+
`Astra toolbox`_ is a toolbox for GPU-accelerated tomography which has very flexible projector geometries that can be used for non-standard CAL systems. If Astra installation fails, go to the Astra Github repository and download the `Mex and Tools`_ folders and place them in a folder inside the source folder in which CAL-software-Matlab is installed.
48+
3649
.. _`CAL-software-Matlab`: https://github.com/computed-axial-lithography/CAL-software-Matlab
3750
.. _`release`: https://github.com/computed-axial-lithography/CAL-software-Matlab/releases
51+
.. _`Astra toolbox`: https://github.com/astra-toolbox/astra-toolbox
52+
.. _`Mex and Tools`: https://github.com/astra-toolbox/astra-toolbox/tree/master/matlab
3853

3954
Uninstallation
4055
--------------

docs/sec_usage_projopt.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
Projection generation and optimization
77
######################################
88

9+
Projection
10+
----------
11+
912
With the target prepared, the projection generation and optimization can begin. The class :class:`CALOptimize` is used to perform projection generation and optimization. First, define the projection parameters and the optimization parameters (these are just some examples for demonstration, more information about these parameters can be found in the :ref:`optimization` code reference:
1013
::
1114
% define projection parameters
@@ -17,6 +20,21 @@ With the target prepared, the projection generation and optimization can begin.
1720
opt_params.threshold = 0.8;
1821
opt_params.learning_rate = 0.005;
1922

23+
The default projection geometry is parallel beam perpendicular to the axis of rotation. However, there are other possible projections geometries including cone beam and laminographic (parallel or cone beam) geometries. These are selected by specifying non-zero ``proj_params``: ``cone_angle`` and/or ``incline_angle`` in degrees. **Additionally,** ``proj_params.CUDA`` **must be set to true to enable these geometries (which implies that your PC has a NVIDIA CUDA GPU).** These geometries are depicted in the figure below.
24+
25+
Parallel beam laminography where :math:`\varphi` is the incline angle which is set with the parameter ``proj_params.incline_angle`` = :math:`\varphi`.
26+
27+
.. image:: images/Laminography_parallel.jpg
28+
:width: 500
29+
30+
Cone beam where :math:`\beta` is the maximum cone angle along the z-axis which is set with the parameter ``proj_params.cone_angle`` = :math:`\beta`.
31+
32+
.. image:: images/Cone_beam.jpg
33+
:width: 500
34+
35+
36+
Optimization
37+
------------
2038
Then initialize the class :class:`CALOptimize` with these parameters and the :class:`TargetObj` created above:
2139
::
2240
% instantiate the optimization class

package_files/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CAL-software-Matlab.mltbx filter=lfs diff=lfs merge=lfs -text
-16.5 MB
Binary file not shown.

package_files/CAL-software-Matlab.prj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
This code package is provided to support the generation of the light projections and the control of a DLP projector through Matlab.</param.description>
1111
<param.screenshot>F:\Github\CAL-software-Matlab\docs\images\title.png</param.screenshot>
12-
<param.version>1.4.1</param.version>
12+
<param.version>1.5.0</param.version>
1313
<param.output>${PROJECT_ROOT}\CAL-software-Matlab.mltbx</param.output>
1414
<param.products.name />
1515
<param.products.id />
@@ -102,6 +102,8 @@ This code package is provided to support the generation of the light projections
102102
<fileset.rootfiles>
103103
<file>F:\Github\CAL-software-Matlab\src\.gitignore</file>
104104
<file>F:\Github\CAL-software-Matlab\src\archive</file>
105+
<file>F:\Github\CAL-software-Matlab\src\astra</file>
106+
<file>F:\Github\CAL-software-Matlab\src\astratesting.m</file>
105107
<file>F:\Github\CAL-software-Matlab\src\autoArrangeFigures_bin</file>
106108
<file>F:\Github\CAL-software-Matlab\src\CALCreateImageSet.m</file>
107109
<file>F:\Github\CAL-software-Matlab\src\CALMetrics.m</file>
@@ -112,7 +114,6 @@ This code package is provided to support the generation of the light projections
112114
<file>F:\Github\CAL-software-Matlab\src\CALProjectorConstructor.m</file>
113115
<file>F:\Github\CAL-software-Matlab\src\CALSetup.m</file>
114116
<file>F:\Github\CAL-software-Matlab\src\CALtest.m</file>
115-
<file>F:\Github\CAL-software-Matlab\src\clipToCircle.m</file>
116117
<file>F:\Github\CAL-software-Matlab\src\colormaps_bin</file>
117118
<file>F:\Github\CAL-software-Matlab\src\createTarget.m</file>
118119
<file>F:\Github\CAL-software-Matlab\src\Display.m</file>
@@ -125,8 +126,10 @@ This code package is provided to support the generation of the light projections
125126
<file>F:\Github\CAL-software-Matlab\src\imshow_3D_bin</file>
126127
<file>F:\Github\CAL-software-Matlab\src\LICENSE.txt</file>
127128
<file>F:\Github\CAL-software-Matlab\src\loadExStlFilename.m</file>
128-
<file>F:\Github\CAL-software-Matlab\src\Projector2D.m</file>
129-
<file>F:\Github\CAL-software-Matlab\src\Projector3D.m</file>
129+
<file>F:\Github\CAL-software-Matlab\src\Projector2DParallel.m</file>
130+
<file>F:\Github\CAL-software-Matlab\src\Projector3DConeCUDA.m</file>
131+
<file>F:\Github\CAL-software-Matlab\src\Projector3DParallel.m</file>
132+
<file>F:\Github\CAL-software-Matlab\src\Projector3DParallelCUDA.m</file>
130133
<file>F:\Github\CAL-software-Matlab\src\ProjObj.m</file>
131134
<file>F:\Github\CAL-software-Matlab\src\PTB.m</file>
132135
<file>F:\Github\CAL-software-Matlab\src\ReconObj.m</file>

src/CALCreateImageSet.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
%{
2+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3+
Copyright (C) 2020-2021 Hayden Taylor Lab, University of California, Berkeley
4+
Website https://github.com/computed-axial-lithography/CAL-software-Matlab
5+
6+
This file is part of the CAL-software-Matlab toolbox.
7+
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation, either version 3 of the License, or
11+
(at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21+
%}
122
classdef CALCreateImageSet
223

324
properties

src/CALMetrics.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
%{
2+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3+
Copyright (C) 2020-2021 Hayden Taylor Lab, University of California, Berkeley
4+
Website https://github.com/computed-axial-lithography/CAL-software-Matlab
5+
6+
This file is part of the CAL-software-Matlab toolbox.
7+
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation, either version 3 of the License, or
11+
(at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21+
%}
122
classdef CALMetrics
223

324
properties

src/CALOptimize.m

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
%{
2+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3+
Copyright (C) 2020-2021 Hayden Taylor Lab, University of California, Berkeley
4+
Website https://github.com/computed-axial-lithography/CAL-software-Matlab
5+
6+
This file is part of the CAL-software-Matlab toolbox.
7+
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation, either version 3 of the License, or
11+
(at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21+
%}
122
classdef CALOptimize
223

324
properties
@@ -51,6 +72,7 @@
5172

5273
obj.thresholds = zeros(1,opt_params.max_iter);
5374
obj.error = zeros(1,opt_params.max_iter);
75+
5476
end
5577

5678
function [obj] = parseParams(obj,opt_params,proj_params)
@@ -155,21 +177,22 @@
155177

156178

157179
mu = curr_threshold;
158-
mu_dilated = (1-obj.opt_params.Rho)*curr_threshold;
159-
mu_eroded = (1+obj.opt_params.Rho)*curr_threshold;
180+
% mu_dilated = (1-obj.opt_params.Rho)*curr_threshold;
181+
% mu_eroded = (1+obj.opt_params.Rho)*curr_threshold;
160182

161183

162184
x_thresh = obj.sigmoid((x-mu), obj.opt_params.sigmoid);
163-
x_thresh_eroded = obj.sigmoid((x-mu_eroded), obj.opt_params.sigmoid);
164-
x_thresh_dilated = obj.sigmoid((x-mu_dilated), obj.opt_params.sigmoid);
165-
185+
% x_thresh_eroded = obj.sigmoid((x-mu_eroded), obj.opt_params.sigmoid);
186+
% x_thresh_dilated = obj.sigmoid((x-mu_dilated), obj.opt_params.sigmoid);
166187

167-
delta_x = (x_thresh - obj.target_obj.target).*obj.target_obj.target_care_area; % Target space error
168-
delta_x_eroded = (x_thresh_eroded - obj.target_obj.target).*obj.target_obj.target_care_area; % Eroded version
169-
delta_x_dilated = (x_thresh_dilated - obj.target_obj.target).*obj.target_obj.target_care_area; % Dilated version
170188

171-
delta_x_feedback = (delta_x + delta_x_eroded + delta_x_dilated)/3;
189+
delta_x = (x_thresh - obj.target_obj.target);%.*obj.target_obj.target_care_area; % Target space error
190+
% delta_x_eroded = (x_thresh_eroded - obj.target_obj.target).*obj.target_obj.target_care_area; % Eroded version
191+
% delta_x_dilated = (x_thresh_dilated - obj.target_obj.target).*obj.target_obj.target_care_area; % Dilated version
172192

193+
% delta_x_feedback = (delta_x + delta_x_eroded + delta_x_dilated)/3;
194+
delta_x_feedback = delta_x;
195+
173196
obj.error(curr_iter) = CALMetrics.calcVER(obj.target_obj.target,x);
174197

175198
delta_b = obj.A.forward(delta_x_feedback);

0 commit comments

Comments
 (0)