diff options
author | Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl> | 2016-07-28 17:05:24 +0200 |
---|---|---|
committer | Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl> | 2016-07-28 17:05:24 +0200 |
commit | b2611a03577c285ddf48edab0d05dafa09ab362c (patch) | |
tree | c1d2f1b5166ba23f55e68e8faf0832f7c540f787 /matlab/tools | |
parent | 1ff4a270a7df1edb54dd91fe653d6a936b959b3a (diff) | |
parent | 53249b3ad63f0d08b9862a75602acf263d230d77 (diff) | |
download | astra-b2611a03577c285ddf48edab0d05dafa09ab362c.tar.gz astra-b2611a03577c285ddf48edab0d05dafa09ab362c.tar.bz2 astra-b2611a03577c285ddf48edab0d05dafa09ab362c.tar.xz astra-b2611a03577c285ddf48edab0d05dafa09ab362c.zip |
Merge branch 'master' into parvec
Diffstat (limited to 'matlab/tools')
-rw-r--r-- | matlab/tools/astra_create_fbp_reconstruction.m | 1 | ||||
-rw-r--r-- | matlab/tools/astra_create_projector.m | 9 | ||||
-rw-r--r-- | matlab/tools/astra_create_reconstruction_cuda.m | 2 | ||||
-rw-r--r-- | matlab/tools/astra_create_vol_geom.m | 15 | ||||
-rw-r--r-- | matlab/tools/astra_mex_direct.m | 24 | ||||
-rw-r--r-- | matlab/tools/astra_mex_plugin.m | 24 | ||||
-rw-r--r-- | matlab/tools/opTomo.m | 79 |
7 files changed, 100 insertions, 54 deletions
diff --git a/matlab/tools/astra_create_fbp_reconstruction.m b/matlab/tools/astra_create_fbp_reconstruction.m index 5540f27..a2561b7 100644 --- a/matlab/tools/astra_create_fbp_reconstruction.m +++ b/matlab/tools/astra_create_fbp_reconstruction.m @@ -19,6 +19,7 @@ cfg.ProjectorId = proj_id; cfg.Options.GPUindex = 0; alg_id = astra_mex_algorithm('create', cfg); astra_mex_algorithm('run', alg_id); +astra_mex_algorithm('delete', alg_id); if numel(sinogram) ~= 1 astra_mex_data2d('delete', sinogram_id); diff --git a/matlab/tools/astra_create_projector.m b/matlab/tools/astra_create_projector.m index da9c083..9bbef9e 100644 --- a/matlab/tools/astra_create_projector.m +++ b/matlab/tools/astra_create_projector.m @@ -1,7 +1,7 @@ -function proj_id = astra_create_projector(type, proj_geom, vol_geom) +function proj_id = astra_create_projector(type, proj_geom, vol_geom, options) %-------------------------------------------------------------------------- -% proj_id = astra_create_projector(type, proj_geom, vol_geom) +% proj_id = astra_create_projector(type, proj_geom, vol_geom, options) % % Create a new projector object based on projection and volume geometry. % Used when the default values of each projector are sufficient. @@ -9,6 +9,7 @@ function proj_id = astra_create_projector(type, proj_geom, vol_geom) % type: type of the projector. 'blob', 'line', 'linear' 'strip', ... See API for more information. % proj_geom: MATLAB struct containing the projection geometry. % vol_geom: MATLAB struct containing the volume geometry. +% options: Optional MATLAB struct containing projector options (like: 'GPUindex', 'DetectorSuperSampling', and 'VoxelSuperSampling') % proj_id: identifier of the projector as it is now stored in the astra-library. %-------------------------------------------------------------------------- %-------------------------------------------------------------------------- @@ -38,6 +39,10 @@ if strcmp(type,'blob') cfg_proj.Kernel.KernelValues = blob_values; end +if exist('options', 'var') + cfg_proj.options = options; +end + if strcmp(type,'linear3d') || strcmp(type,'linearcone') || strcmp(type,'cuda3d') proj_id = astra_mex_projector3d('create', cfg_proj); else diff --git a/matlab/tools/astra_create_reconstruction_cuda.m b/matlab/tools/astra_create_reconstruction_cuda.m index 7d9e1dd..7d0421c 100644 --- a/matlab/tools/astra_create_reconstruction_cuda.m +++ b/matlab/tools/astra_create_reconstruction_cuda.m @@ -45,7 +45,7 @@ if strcmp(rec_type,'') end % configure -cfg = astra_struct('SIRT_CUDA'); +cfg = astra_struct(rec_type); cfg.ProjectionGeometry = proj_geom; cfg.ReconstructionGeometry = vol_geom; cfg.ProjectionDataId = sinogram_id; diff --git a/matlab/tools/astra_create_vol_geom.m b/matlab/tools/astra_create_vol_geom.m index ea975e6..a3ba7de 100644 --- a/matlab/tools/astra_create_vol_geom.m +++ b/matlab/tools/astra_create_vol_geom.m @@ -15,6 +15,7 @@ function vol_geom = astra_create_vol_geom(varargin) % vol_geom: MATLAB struct containing all information of the geometry. %-------------------------------------------------------------------------- % vol_geom = astra_create_vol_geom(row_count, col_count, slice_count); +% vol_geom = astra_create_vol_geom(row_count, col_count, slice_count, min_x, max_x, min_y, max_y, min_z, max_z); % % Create a 3D volume geometry. See the API for more information. % row_count: number of rows. @@ -93,4 +94,18 @@ elseif numel(varargin) == 3 vol_geom.GridRowCount = varargin{1}; vol_geom.GridColCount = varargin{2}; vol_geom.GridSliceCount = varargin{3}; + +% astra_create_vol_geom(row_count, col_count, slice_count, min_x, max_x, min_y, max_y, min_z, max_z) +elseif numel(varargin) == 9 + vol_geom = struct(); + vol_geom.GridRowCount = varargin{1}; + vol_geom.GridColCount = varargin{2}; + vol_geom.GridSliceCount = varargin{3}; + vol_geom.option.WindowMinX = varargin{4}; + vol_geom.option.WindowMaxX = varargin{5}; + vol_geom.option.WindowMinY = varargin{6}; + vol_geom.option.WindowMaxY = varargin{7}; + vol_geom.option.WindowMinZ = varargin{8}; + vol_geom.option.WindowMaxZ = varargin{9}; + end diff --git a/matlab/tools/astra_mex_direct.m b/matlab/tools/astra_mex_direct.m new file mode 100644 index 0000000..58c4fd2 --- /dev/null +++ b/matlab/tools/astra_mex_direct.m @@ -0,0 +1,24 @@ +function [varargout] = astra_mex_direct(varargin) +%------------------------------------------------------------------------ +% Reference page in Help browser +% <a href="matlab:docsearch('astra_mex_direct' )">astra_mex_data3d</a>. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the ASTRA Toolbox +% +% Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp +% 2014-2015, CWI, Amsterdam +% License: Open Source under GPLv3 +% Contact: astra@uantwerpen.be +% Website: http://sf.net/projects/astra-toolbox +%------------------------------------------------------------------------ +% $Id$ +if nargout == 0 + astra_mex_direct_c(varargin{:}); + if exist('ans','var') + varargout{1} = ans; + end +else + varargout = cell(1,nargout); + [varargout{:}] = astra_mex_direct_c(varargin{:}); +end diff --git a/matlab/tools/astra_mex_plugin.m b/matlab/tools/astra_mex_plugin.m new file mode 100644 index 0000000..4159365 --- /dev/null +++ b/matlab/tools/astra_mex_plugin.m @@ -0,0 +1,24 @@ +function [varargout] = astra_mex_plugin(varargin) +%------------------------------------------------------------------------ +% Reference page in Help browser +% <a href="matlab:docsearch('astra_mex_plugin' )">astra_mex_plugin</a>. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the ASTRA Toolbox +% +% Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp +% 2014-2015, CWI, Amsterdam +% License: Open Source under GPLv3 +% Contact: astra@uantwerpen.be +% Website: http://sf.net/projects/astra-toolbox +%------------------------------------------------------------------------ +% $Id$ +if nargout == 0 + astra_mex_plugin_c(varargin{:}); + if exist('ans','var') + varargout{1} = ans; + end +else + varargout = cell(1,nargout); + [varargout{:}] = astra_mex_plugin_c(varargin{:}); +end
\ No newline at end of file diff --git a/matlab/tools/opTomo.m b/matlab/tools/opTomo.m index 14128d2..04b3634 100644 --- a/matlab/tools/opTomo.m +++ b/matlab/tools/opTomo.m @@ -44,11 +44,9 @@ classdef opTomo < opSpot vol_id fp_alg_id bp_alg_id + proj_id % ASTRA IDs handle astra_handle - % geometries - proj_geom; - vol_geom; end % properties properties ( SetAccess = private, GetAccess = public ) @@ -139,6 +137,17 @@ classdef opTomo < opSpot error(['Only type ' 39 'cuda' 39 ' is supported ' ... 'for 3D geometries.']) end + + % setup projector + cfg = astra_struct('cuda3d'); + cfg.ProjectionGeometry = proj_geom; + cfg.VolumeGeometry = vol_geom; + cfg.option.GPUindex = gpu_index; + + % create projector + op.proj_id = astra_mex_projector3d('create', cfg); + % create handle to ASTRA object, for cleaning up + op.astra_handle = opTomo_helper_handle(op.proj_id); % create a function handle op.funHandle = @opTomo_intrnl3D; @@ -148,8 +157,6 @@ classdef opTomo < opSpot % pass object properties op.proj_size = proj_size; op.vol_size = vol_size; - op.proj_geom = proj_geom; - op.vol_geom = vol_geom; op.cflag = false; op.sweepflag = false; @@ -169,10 +176,12 @@ classdef opTomo < opSpot if issparse(x) x = full(x); end - - % convert input to single - if isa(x, 'single') == false + + if isa(x, 'double') + isdouble = true; x = single(x); + else + isdouble = false; end % the multiplication @@ -180,6 +189,10 @@ classdef opTomo < opSpot % make sure output is column vector y = y(:); + + if isdouble + y = double(y); + end end % multiply @@ -194,7 +207,7 @@ classdef opTomo < opSpot function y = opTomo_intrnl2D(op,x,mode) if mode == 1 - % X is passed as a vector, reshape it into an image. + % x is passed as a vector, reshape it into an image. x = reshape(x, op.vol_size); % Matlab data copied to ASTRA data @@ -206,7 +219,7 @@ classdef opTomo < opSpot % retrieve Matlab array y = astra_mex_data2d('get_single', op.sino_id); else - % X is passed as a vector, reshape it into a sinogram. + % x is passed as a vector, reshape it into a sinogram. x = reshape(x, op.proj_size); % Matlab data copied to ASTRA data @@ -218,6 +231,7 @@ classdef opTomo < opSpot % retrieve Matlab array y = astra_mex_data2d('get_single', op.vol_id); end + end % opTomo_intrnl2D @@ -225,53 +239,16 @@ classdef opTomo < opSpot function y = opTomo_intrnl3D(op,x,mode) if mode == 1 - % X is passed as a vector, reshape it into an image + % x is passed as a vector, reshape it into an image x = reshape(x, op.vol_size); - % initialize output - y = zeros(op.proj_size, 'single'); - - % link matlab array to ASTRA - vol_id = astra_mex_data3d_c('link', '-vol', op.vol_geom, x, 0); - sino_id = astra_mex_data3d_c('link', '-sino', op.proj_geom, y, 1); - - % initialize fp algorithm - cfg = astra_struct('FP3D_CUDA'); - cfg.ProjectionDataId = sino_id; - cfg.VolumeDataId = vol_id; - - alg_id = astra_mex_algorithm('create', cfg); - % forward projection - astra_mex_algorithm('iterate', alg_id); - - % cleanup - astra_mex_data3d('delete', vol_id); - astra_mex_data3d('delete', sino_id); + y = astra_mex_direct('FP3D', op.proj_id, x); else - % X is passed as a vector, reshape it into projection data + % x is passed as a vector, reshape it into projection data x = reshape(x, op.proj_size); - - % initialize output - y = zeros(op.vol_size,'single'); - - % link matlab array to ASTRA - vol_id = astra_mex_data3d_c('link', '-vol', op.vol_geom, y, 1); - sino_id = astra_mex_data3d_c('link', '-sino', op.proj_geom, x, 0); - % initialize bp algorithm - cfg = astra_struct('BP3D_CUDA'); - cfg.ProjectionDataId = sino_id; - cfg.ReconstructionDataId = vol_id; - - alg_id = astra_mex_algorithm('create', cfg); - - % backprojection - astra_mex_algorithm('iterate', alg_id); - - % cleanup - astra_mex_data3d('delete', vol_id); - astra_mex_data3d('delete', sino_id); + y = astra_mex_direct('BP3D', op.proj_id, x); end end % opTomo_intrnl3D |