diff options
Diffstat (limited to 'matlab/tools')
49 files changed, 2350 insertions, 0 deletions
diff --git a/matlab/tools/ROIselectfull.m b/matlab/tools/ROIselectfull.m new file mode 100644 index 0000000..a50c979 --- /dev/null +++ b/matlab/tools/ROIselectfull.m @@ -0,0 +1,18 @@ +function V_out = ROIselectfull(input, ROI) + + s1 = size(input,1); + s2 = size(input,2); + [x y] = meshgrid(-(s2-1)/2:(s2-1)/2,(s1-1)/2:-1:-(s1-1)/2); + A = Afstand(x,y,0,0); + + V_out = zeros(size(input)); + for slice = 1:size(input,3); + V = input(:,:,slice); + V(A > ROI/2) = 0; + V_out(:,:,slice) = V; + end +end + +function A = Afstand(x1,y1,x2,y2) + A = sqrt((x1-x2).^2+(y1-y2).^2); +end
\ No newline at end of file diff --git a/matlab/tools/astra_add_noise_to_sino.m b/matlab/tools/astra_add_noise_to_sino.m new file mode 100644 index 0000000..a262f49 --- /dev/null +++ b/matlab/tools/astra_add_noise_to_sino.m @@ -0,0 +1,47 @@ +function sinogram_out = astra_add_noise_to_sino(sinogram_in,I0) + +%-------------------------------------------------------------------------- +% sinogram_out = astra_add_noise_to_sino(sinogram_in,I0) +% +% Add poisson noise to a sinogram. +% +% sinogram_in: input sinogram, can be either MATLAB-data or an +% astra-identifier. In the latter case, this operation is inplace and the +% result will also be stored in this data object. +% I0: background intensity, used to set noise level, lower equals more +% noise +% sinogram_out: output sinogram in MATLAB-data. +%-------------------------------------------------------------------------- +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + +if numel(sinogram_in) == 1 + sinogramRaw = astra_mex_data2d('get', sinogram_in); +else + sinogramRaw = sinogram_in; +end + +% scale to [0,1] +max_sinogramRaw = max(sinogramRaw(:)); +sinogramRawScaled = sinogramRaw ./ max_sinogramRaw; +% to detector count +sinogramCT = I0 * exp(-sinogramRawScaled); +% add poison noise +sinogramCT_A = sinogramCT * 1e-12; +sinogramCT_B = double(imnoise(sinogramCT_A, 'poisson')); +sinogramCT_C = sinogramCT_B * 1e12; +% to density +sinogramCT_D = sinogramCT_C / I0; +sinogram_out = -max_sinogramRaw * log(sinogramCT_D); + +if numel(sinogram_in) == 1 + astra_mex_data2d('store', sinogram_in, sinogram_out); +end diff --git a/matlab/tools/astra_clear.m b/matlab/tools/astra_clear.m new file mode 100644 index 0000000..d42e395 --- /dev/null +++ b/matlab/tools/astra_clear.m @@ -0,0 +1,19 @@ +%-------------------------------------------------------------------------- +% Clears and frees memory of all objects (data, projectors, algorithms) +% currently in the astra-library. +%-------------------------------------------------------------------------- +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + +astra_mex_data2d('clear'); +astra_mex_data3d('clear'); +astra_mex_algorithm('clear'); +astra_mex_projector('clear'); diff --git a/matlab/tools/astra_create_backprojection.m b/matlab/tools/astra_create_backprojection.m new file mode 100644 index 0000000..7f0b02f --- /dev/null +++ b/matlab/tools/astra_create_backprojection.m @@ -0,0 +1,63 @@ +function [vol_id, vol] = astra_create_backprojection(data, proj_id) + +%-------------------------------------------------------------------------- +% [vol_id, vol] = astra_create_backprojection(data, proj_id) +% +% Create a CPU based back projection. +% +% data: input sinogram, can be either MATLAB-data or an astra-identifier. +% proj_id: identifier of the projector as it is stored in the astra-library +% vol_id: identifier of the volume data object as it is now stored in the astra-library. +% vol: MATLAB data version of the volume +%-------------------------------------------------------------------------- +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + + +% get projection geometry +proj_geom = astra_mex_projector('projection_geometry', proj_id); +vol_geom = astra_mex_projector('volume_geometry', proj_id); + +% store sinogram +if (numel(data) > 1) + sino_id = astra_mex_data2d('create','-sino', proj_geom, data); +else + sino_id = data; +end + +% store volume +vol_id = astra_mex_data2d('create','-vol', vol_geom, 0); + +if astra_mex_projector('is_cuda', proj_id) + cfg = astra_struct('BP_CUDA'); +else + cfg = astra_struct('BP'); +end + +cfg.ProjectorId = proj_id; +cfg.ProjectionDataId = sino_id; +cfg.ReconstructionDataId = vol_id; + +% create backprojection +alg_id = astra_mex_algorithm('create', cfg); +astra_mex_algorithm('iterate', alg_id); +astra_mex_algorithm('delete', alg_id); + +if (numel(data) > 1) + astra_mex_data2d('delete', sino_id); +end + +if nargout >= 2 + vol = astra_mex_data2d('get',vol_id); +end + + + diff --git a/matlab/tools/astra_create_backprojection3d_cuda.m b/matlab/tools/astra_create_backprojection3d_cuda.m new file mode 100644 index 0000000..afa41db --- /dev/null +++ b/matlab/tools/astra_create_backprojection3d_cuda.m @@ -0,0 +1,54 @@ +function [vol_id, vol] = astra_create_backprojection3d_cuda(data, proj_geom, vol_geom) + +%-------------------------------------------------------------------------- +% [vol_id, vol] = astra_create_backprojection3d_cuda(data, proj_geom, vol_geom) +% +% Create a GPU based backprojection. +% +% data: input projection data, can be either MATLAB-data or an astra-identifier. +% proj_geom: MATLAB struct containing the projection geometry. +% vol_geom: MATLAB struct containing the volume geometry. +% vol_id: identifier of the volume data object as it is now stored in +% the astra-library. +% vol: MATLAB data version of the volume. +%-------------------------------------------------------------------------- +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + + +% store projection data +if (numel(data) > 1) + sino_id = astra_mex_data3d('create','-proj3d', proj_geom, data); +else + sino_id = data; +end + +% store volume +vol_id = astra_mex_data3d('create','-vol', vol_geom, 0); + +% create sinogram +cfg = astra_struct('BP3D_CUDA'); +cfg.ProjectionDataId = sino_id; +cfg.ReconstructionDataId = vol_id; +alg_id = astra_mex_algorithm('create', cfg); +astra_mex_algorithm('iterate', alg_id); +astra_mex_algorithm('delete', alg_id); + +if (numel(data) > 1) + astra_mex_data3d('delete', sino_id); +end + +if nargout >= 2 + vol = astra_mex_data3d('get',vol_id); +end + + + diff --git a/matlab/tools/astra_create_backprojection_cuda.m b/matlab/tools/astra_create_backprojection_cuda.m new file mode 100644 index 0000000..cef7864 --- /dev/null +++ b/matlab/tools/astra_create_backprojection_cuda.m @@ -0,0 +1,39 @@ +function backProj = astra_create_backprojection_cuda(sinogramData, proj_geom, vol_geom) + %-------------------------------------------------------------------------- + % backProj = astra_create_backprojection_cuda(sinogramData, proj_geom, vol_geom) + % + % Creates a CUDA-based simple backprojection + % + % sinogramData: 2D matrix with projections stored row-based + % theta: projection angles, length should be equal to the number of rows in + % sinogramData + % reconstructionSize: vector with length 2 with the row and column count of + % the reconstruction image + % backProj: 2D back projection from sinogram data + %-------------------------------------------------------------------------- + %------------------------------------------------------------------------ + % This file is part of the + % All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") + % + % Copyright: iMinds-Vision Lab, University of Antwerp + % License: Open Source under GPLv3 + % Contact: mailto:astra@ua.ac.be + % Website: http://astra.ua.ac.be + %------------------------------------------------------------------------ + % $Id$ + + recon_id = astra_mex_data2d('create', '-vol', vol_geom, 0); + sinogram_id = astra_mex_data2d('create', '-sino', proj_geom, sinogramData); + + cfg = astra_struct('BP_CUDA'); + cfg.ProjectionDataId = sinogram_id; + cfg.ReconstructionDataId = recon_id; + + alg_id = astra_mex_algorithm('create', cfg); + astra_mex_algorithm('run', alg_id); + backProj = astra_mex_data2d('get', recon_id); + + astra_mex_data2d('delete', sinogram_id); + astra_mex_data2d('delete', recon_id); + astra_mex_algorithm('delete', alg_id); +end diff --git a/matlab/tools/astra_create_fbp_reconstruction.m b/matlab/tools/astra_create_fbp_reconstruction.m new file mode 100644 index 0000000..4456f9c --- /dev/null +++ b/matlab/tools/astra_create_fbp_reconstruction.m @@ -0,0 +1,23 @@ +function [FBP_id, FBP] = astra_create_fbp_reconstruction(sinogram, proj_id) + +proj_geom = astra_mex_projector('projection_geometry', proj_id); +vol_geom = astra_mex_projector('volume_geometry', proj_id); + +if numel(sinogram) == 1 + sinogram_id = sinogram; +else + sinogram_id = astra_mex_data2d('create', '-sino', proj_geom, sinogram); +end + +FBP_id = astra_mex_data2d('create','-vol',vol_geom, 0); + +cfg = astra_struct('FBP_CUDA'); +cfg.ProjectionDataId = sinogram_id; +cfg.ReconstructionDataId = FBP_id; +cfg.FilterType = 'Ram-Lak'; +cfg.ProjectorId = proj_id; +cfg.Options.GPUindex = 0; +alg_id = astra_mex_algorithm('create', cfg); +astra_mex_algorithm('run', alg_id); + +FBP = astra_mex_data2d('get', FBP_id); diff --git a/matlab/tools/astra_create_proj_geom.m b/matlab/tools/astra_create_proj_geom.m new file mode 100644 index 0000000..dbf0464 --- /dev/null +++ b/matlab/tools/astra_create_proj_geom.m @@ -0,0 +1,204 @@ +function proj_geom = astra_create_proj_geom(type, varargin) + +%-------------------------------------------------------------------------- +% proj_geom = astra_create_proj_geom('parallel', det_width, det_count, angles) +% +% Create a 2D parallel beam geometry. See the API for more information. +% det_width: distance between two adjacent detectors +% det_count: number of detectors in a single projection +% angles: projection angles in radians, should be between -pi/4 and 7pi/4 +% proj_geom: MATLAB struct containing all information of the geometry +%-------------------------------------------------------------------------- +% proj_geom = astra_create_proj_geom('parallel3d', det_spacing_x, det_spacing_y, det_row_count, det_col_count, angles) +% +% Create a 3D parallel beam geometry. See the API for more information. +% det_spacing_x: distance between two horizontally adjacent detectors +% det_spacing_y: distance between two vertically adjacent detectors +% det_row_count: number of detector rows in a single projection +% det_col_count: number of detector columns in a single projection +% angles: projection angles in radians, should be between -pi/4 and 7pi/4 +% proj_geom: MATLAB struct containing all information of the geometry +%-------------------------------------------------------------------------- +% proj_geom = astra_create_proj_geom('fanflat', det_width, det_count, angles, source_origin, origin_det) +% +% Create a 2D flat fan beam geometry. See the API for more information. +% det_width: distance between two adjacent detectors +% det_count: number of detectors in a single projection +% angles: projection angles in radians, should be between -pi/4 and 7pi/4 +% source_origin: distance between the source and the center of rotation +% origin_det: distance between the center of rotation and the detector array +% proj_geom: MATLAB struct containing all information of the geometry +%-------------------------------------------------------------------------- +% proj_geom = astra_create_proj_geom('fanflat_vec', det_count, vectors) +% +% Create a 2D flat fan beam geometry specified by 2D vectors. +% See the API for more information. +% det_count: number of detectors in a single projection +% vectors: a matrix containing the actual geometry. Each row corresponds +% to a single projection, and consists of: +% ( srcX, srcY, dX, dY, uX, uY ) +% src: the ray source +% d : the center of the detector +% u : the vector from detector pixel 0 to 1 +% proj_geom: MATLAB struct containing all information of the geometry +%-------------------------------------------------------------------------- +% proj_geom = astra_create_proj_geom('cone', det_spacing_x, det_spacing_y, det_row_count, det_col_count, angles, source_origin, origin_det) +% +% Create a 3D cone beam geometry. See the API for more information. +% det_spacing_x: distance between two horizontally adjacent detectors +% det_spacing_y: distance between two vertically adjacent detectors +% det_row_count: number of detector rows in a single projection +% det_col_count: number of detector columns in a single projection +% angles: projection angles in radians, should be between -pi/4 and 7pi/4 +% source_origin: distance between the source and the center of rotation +% origin_det: distance between the center of rotation and the detector array +% proj_geom: MATLAB struct containing all information of the geometry +%-------------------------------------------------------------------------- +% proj_geom = astra_create_proj_geom('cone_vec', det_row_count, det_col_count, vectors) +% +% Create a 3D cone beam geometry specified by 3D vectors. +% See the API for more information. +% det_row_count: number of detector rows in a single projection +% det_col_count: number of detector columns in a single projection +% vectors: a matrix containing the actual geometry. Each row corresponds +% to a single projection, and consists of: +% ( srcX, srcY, srcZ, dX, dY, dZ, uX, uY, uZ, vX, vY, vZ ) +% src: the ray source +% d : the center of the detector +% u : the vector from detector pixel (0,0) to (0,1) +% v : the vector from detector pixel (0,0) to (1,0) +% proj_geom: MATLAB struct containing all information of the geometry +%-------------------------------------------------------------------------- +% proj_geom = astra_create_proj_geom('parallel3d_vec', det_row_count, det_col_count, vectors) +% +% Create a 3D parallel beam geometry specified by 3D vectors. +% See the API for more information. +% det_row_count: number of detector rows in a single projection +% det_col_count: number of detector columns in a single projection +% vectors: a matrix containing the actual geometry. Each row corresponds +% to a single projection, and consists of: +% ( rayX, rayY, rayZ, dX, dY, dZ, uX, uY, uZ, vX, vY, vZ ) +% ray: the ray direction +% d : the center of the detector +% u : the vector from detector pixel (0,0) to (0,1) +% v : the vector from detector pixel (0,0) to (1,0) +% proj_geom: MATLAB struct containing all information of the geometry +%-------------------------------------------------------------------------- +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + + +if strcmp(type,'parallel') + if numel(varargin) < 3 + error('not enough variables: astra_create_proj_geom(parallel, detector_spacing, det_count, angles)'); + end + proj_geom = struct( ... + 'type', 'parallel', ... + 'DetectorWidth', varargin{1}, ... + 'DetectorCount', varargin{2}, ... + 'ProjectionAngles', varargin{3} ... + ); + +elseif strcmp(type,'fanflat') + if numel(varargin) < 5 + error('not enough variables: astra_create_proj_geom(fanflat, det_width, det_count, angles, source_origin, source_det)'); + end + proj_geom = struct( ... + 'type', 'fanflat', ... + 'DetectorWidth', varargin{1}, ... + 'DetectorCount', varargin{2}, ... + 'ProjectionAngles', varargin{3}, ... + 'DistanceOriginSource', varargin{4}, ... + 'DistanceOriginDetector', varargin{5} ... + ); + +elseif strcmp(type,'fanflat_vec') + if numel(varargin) < 2 + error('not enough variables: astra_create_proj_geom(fanflat_vec, det_count, V') + end + if size(varargin{2}, 2) ~= 6 + error('V should be a Nx6 matrix, with N the number of projections') + end + proj_geom = struct( ... + 'type', 'fanflat_vec', ... + 'DetectorCount', varargin{1}, ... + 'Vectors', varargin{2} ... + ); + +elseif strcmp(type,'parallel3d') + if numel(varargin) < 5 + error('not enough variables: astra_create_proj_geom(parallel3d, detector_spacing_x, detector_spacing_y, det_row_count, det_col_count, angles)'); + end + proj_geom = struct( ... + 'type', 'parallel3d', ... + 'DetectorSpacingX', varargin{1}, ... + 'DetectorSpacingY', varargin{2}, ... + 'DetectorRowCount', varargin{3}, ... + 'DetectorColCount', varargin{4}, ... + 'ProjectionAngles', varargin{5} ... + ); +elseif strcmp(type,'cone') + if numel(varargin) < 7 + error('not enough variables: astra_create_proj_geom(cone, detector_spacing_x, detector_spacing_y, det_row_count, det_col_count, angles, source_origin, source_det)'); + end + proj_geom = struct( ... + 'type', 'cone', ... + 'DetectorSpacingX', varargin{1}, ... + 'DetectorSpacingY', varargin{2}, ... + 'DetectorRowCount', varargin{3}, ... + 'DetectorColCount', varargin{4}, ... + 'ProjectionAngles', varargin{5}, ... + 'DistanceOriginSource', varargin{6}, ... + 'DistanceOriginDetector',varargin{7} ... + ); +elseif strcmp(type,'cone_vec') + if numel(varargin) < 3 + error('not enough variables: astra_create_proj_geom(cone_vec, det_row_count, det_col_count, V') + end + if size(varargin{3}, 2) ~= 12 + error('V should be a Nx12 matrix, with N the number of projections') + end + proj_geom = struct( ... + 'type', 'cone_vec', ... + 'DetectorRowCount', varargin{1}, ... + 'DetectorColCount', varargin{2}, ... + 'Vectors', varargin{3} ... + ); +elseif strcmp(type,'parallel3d_vec') + if numel(varargin) < 3 + error('not enough variables: astra_create_proj_geom(parallel3d_vec, det_row_count, det_col_count, V') + end + if size(varargin{3}, 2) ~= 12 + error('V should be a Nx12 matrix, with N the number of projections') + end + proj_geom = struct( ... + 'type', 'parallel3d_vec', ... + 'DetectorRowCount', varargin{1}, ... + 'DetectorColCount', varargin{2}, ... + 'Vectors', varargin{3} ... + ); +elseif strcmp(type,'sparse_matrix') + if numel(varargin) < 3 + error('not enough variables: astra_create_proj_geom(sparse_matrix, det_width, det_count, angles, matrix_id)') + end + proj_geom = struct( ... + 'type', 'sparse_matrix', ... + 'DetectorWidth', varargin{1}, ... + 'DetectorCount', varargin{2}, ... + 'ProjectionAngles', varargin{3}, ... + 'MatrixID', varargin{4} ... + ); + +else + disp(['Error: unknown type ' type]); + proj_geom = struct(); +end + diff --git a/matlab/tools/astra_create_projector.m b/matlab/tools/astra_create_projector.m new file mode 100644 index 0000000..f773d0d --- /dev/null +++ b/matlab/tools/astra_create_projector.m @@ -0,0 +1,50 @@ +function proj_id = astra_create_projector(type, proj_geom, vol_geom) + +%-------------------------------------------------------------------------- +% proj_id = astra_create_projector(type, proj_geom, vol_geom) +% +% Create a new projector object based on projection and volume geometry. +% Used when the default values of each projector are sufficient. +% +% 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. +% proj_id: identifier of the projector as it is now stored in the astra-library. +%-------------------------------------------------------------------------- +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + + +cfg_proj = astra_struct(type); +cfg_proj.ProjectionGeometry = proj_geom; +cfg_proj.VolumeGeometry = vol_geom; + +if strcmp(type,'blob') + % Blob options + blob_size = 2; + blob_sample_rate = 0.01; + blob_values = kaiserBessel(2, 10.4, blob_size, 0:blob_sample_rate:blob_size); + cfg_proj.Kernel.KernelSize = blob_size; + cfg_proj.Kernel.SampleRate = blob_sample_rate; + cfg_proj.Kernel.SampleCount = length(blob_values); + cfg_proj.Kernel.KernelValues = blob_values; +end + +if strcmp(type,'linear3d') || strcmp(type,'linearcone') || strcmp(type,'cuda3d') + proj_id = astra_mex_projector3d('create', cfg_proj); +else + proj_id = astra_mex_projector('create', cfg_proj); +end + + + + + diff --git a/matlab/tools/astra_create_reconstruction.m b/matlab/tools/astra_create_reconstruction.m new file mode 100644 index 0000000..15e452c --- /dev/null +++ b/matlab/tools/astra_create_reconstruction.m @@ -0,0 +1,97 @@ +function [recon_id, recon] = astra_create_reconstruction(rec_type, proj_id, sinogram, iterations, use_mask, mask, use_minc, minc, use_maxc, maxc) + +%-------------------------------------------------------------------------- +% [recon_id, recon] = astra_create_reconstruction(rec_type, proj_id, sinogram, iterations, use_mask, mask, use_minc, minc, use_maxc, maxc) +% +% Create a CPU based iterative reconstruction. +% +% rec_type: reconstruction type, 'ART', 'SART' 'SIRT' or 'CGLS', not all options are adjustable +% proj_id: identifier of the projector as it is stored in the astra-library +% sinogram: sinogram data OR sinogram identifier +% iterations: number of iterations to perform +% use_mask: use a reconstrucionmask? 'yes' or 'no' +% mask: mask data OR mask identifier. +% use_minc: use a minimum constraint? 'yes' or 'no' +% minc: minimum constraint value +% use_maxc: use a maximum constraint? 'yes' or 'no' +% maxc: maximum constraint value +% recon_id: identifier of the reconstruction data object as it is now stored in the astra-library +% recon: MATLAB data version of the reconstruction +%-------------------------------------------------------------------------- +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + + +if nargin <= 4 + use_mask = 'no'; + mask = []; + use_minc = 'no'; + minc = 0; + use_maxc = 'no'; + maxc = 255; +end + +if nargin <= 6 + use_minc = 'no'; + minc = 0; + use_maxc = 'no'; + maxc = 255; +end + +if numel(sinogram) == 1 + sinogram_id = sinogram; +else + proj_geom = astra_mex_projector('projection_geometry', proj_id); + sinogram_id = astra_mex_data2d('create', '-sino', proj_geom, sinogram); +end + +% create reconstruction object +vol_geom = astra_mex_projector('volume_geometry', proj_id); +recon_id = astra_mex_data2d('create', '-vol', vol_geom, 0); + +% configure +cfg = astra_struct(rec_type); +cfg.ProjectorId = proj_id; +cfg.ProjectionDataId = sinogram_id; +cfg.ReconstructionDataId = recon_id; +if strcmp(use_mask,'yes') + if numel(mask) == 1 + mask_id = mask; + else + mask_id = astra_mex_data2d('create', '-vol', vol_geom, mask); + end + cfg.options.ReconstructionMaskId = mask_id; +end +cfg.options.UseMinConstraint = use_minc; +cfg.options.MinConstraintValue = minc; +cfg.options.UseMaxConstraint = use_maxc; +cfg.options.MaxConstraintValue = maxc; +cfg.options.ProjectionOrder = 'random'; +alg_id = astra_mex_algorithm('create', cfg); + +% iterate +astra_mex_algorithm('iterate', alg_id, iterations); + +% return object +recon = astra_mex_data2d('get', recon_id); + +% garbage collection +astra_mex_algorithm('delete', alg_id); +if numel(sinogram) ~= 1 + astra_mex_data2d('delete', sinogram_id); +end + +if strcmp(use_mask,'yes') + if numel(mask) ~= 1 + astra_mex_data2d('delete', mask_id); + end +end + diff --git a/matlab/tools/astra_create_reconstruction_cuda.m b/matlab/tools/astra_create_reconstruction_cuda.m new file mode 100644 index 0000000..b428eb5 --- /dev/null +++ b/matlab/tools/astra_create_reconstruction_cuda.m @@ -0,0 +1,80 @@ +function [recon_id, recon] = astra_create_reconstruction_cuda(rec_type, proj_geom, vol_geom, sinogram, iterations, use_mask, mask, use_minc, minc, use_maxc, maxc) + +%-------------------------------------------------------------------------- +% [recon_id, recon] = astra_create_reconstruction_cuda(rec_type, proj_geom, vol_geom, sinogram, iterations, use_mask, mask, use_minc, minc, use_maxc, maxc) +% +% Create a GPU based iterative reconstruction. +% +% rec_type: reconstruction type, only 'SIRT_CUDA' for now +% proj_geom: projection geometry struct +% vol_geom: volume geometry struct +% sinogram: sinogram data OR sinogram identifier +% iterations: number of iterations to perform +% use_mask: use a reconstrucionmask? 'yes' or 'no' +% mask: mask data OR mask identifier. +% use_minc: use a minimum constraint? 'yes' or 'no' +% minc: minimum constraint value +% use_maxc: use a maximum constraint? 'yes' or 'no' +% maxc: maximum constraint value +% recon_id: identifier of the reconstruction data object as it is now stored in the astra-library +% recon: MATLAB data version of the reconstruction +%-------------------------------------------------------------------------- +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + + +if numel(sinogram) == 1 + sinogram_id = sinogram; +else + sinogram_id = astra_mex_data2d('create', '-sino', proj_geom, sinogram); +end + +% create reconstruction object +recon_id = astra_mex_data2d('create', '-vol', vol_geom, 0); + +% configure +cfg = astra_struct('SIRT_CUDA'); +cfg.ProjectionGeometry = proj_geom; +cfg.ReconstructionGeometry = vol_geom; +cfg.ProjectionDataId = sinogram_id; +cfg.ReconstructionDataId = recon_id; +if strcmp(use_mask,'yes') + if numel(mask) == 1 + mask_id = mask; + else + mask_id = astra_mex_data2d('create', '-vol', vol_geom, mask); + end + cfg.options.ReconstructionMaskId = mask_id; +end +cfg.options.UseMinConstraint = use_minc; +cfg.options.MinConstraintValue = minc; +cfg.options.UseMaxConstraint = use_maxc; +cfg.options.MaxConstraintValue = maxc; +alg_id = astra_mex_algorithm('create', cfg); + +% iterate +astra_mex_algorithm('iterate', alg_id, iterations); + +% return object +recon = astra_mex_data2d('get', recon_id); + +% garbage collection +astra_mex_algorithm('delete', alg_id); +if numel(sinogram) ~= 1 + astra_mex_data2d('delete', sinogram_id); +end + +if strcmp(use_mask,'yes') + if numel(mask) ~= 1 + astra_mex_data2d('delete', mask_id); + end +end + diff --git a/matlab/tools/astra_create_sino.m b/matlab/tools/astra_create_sino.m new file mode 100644 index 0000000..4771bd6 --- /dev/null +++ b/matlab/tools/astra_create_sino.m @@ -0,0 +1,63 @@ +function [sino_id, sino] = astra_create_sino(data, proj_id) + +%-------------------------------------------------------------------------- +% [sino_id, sino] = astra_create_sino(data, proj_id) +% +% Create a CPU based forward projection. +% +% data: input volume, can be either MATLAB-data or an astra-identifier. +% proj_id: identifier of the projector as it is stored in the astra-library +% sino_id: identifier of the sinogram data object as it is now stored in the astra-library. +% sino: MATLAB data version of the sinogram +%-------------------------------------------------------------------------- +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + + +% get projection geometry +proj_geom = astra_mex_projector('projection_geometry', proj_id); +vol_geom = astra_mex_projector('volume_geometry', proj_id); + +% store volume +if (numel(data) > 1) + volume_id = astra_mex_data2d('create','-vol', vol_geom, data); +else + volume_id = data; +end + +% store sino +sino_id = astra_mex_data2d('create','-sino', proj_geom, 0); + +if astra_mex_projector('is_cuda', proj_id) + cfg = astra_struct('FP_CUDA'); +else + cfg = astra_struct('FP'); +end + +cfg.ProjectorId = proj_id; +cfg.ProjectionDataId = sino_id; +cfg.VolumeDataId = volume_id; + +% create sinogram +alg_id = astra_mex_algorithm('create', cfg); +astra_mex_algorithm('iterate', alg_id); +astra_mex_algorithm('delete', alg_id); + +if (numel(data) > 1) + astra_mex_data2d('delete', volume_id); +end + +if nargout >= 2 + sino = astra_mex_data2d('get',sino_id); +end + + + diff --git a/matlab/tools/astra_create_sino3d_cuda.m b/matlab/tools/astra_create_sino3d_cuda.m new file mode 100644 index 0000000..ef22ebe --- /dev/null +++ b/matlab/tools/astra_create_sino3d_cuda.m @@ -0,0 +1,54 @@ +function [sino_id, sino] = astra_create_sino3d_cuda(data, proj_geom, vol_geom) + +%-------------------------------------------------------------------------- +% [sino_id, sino] = astra_create_sino3d_cuda(data, proj_geom, vol_geom) +% +% Create a GPU based forward projection. +% +% data: input volume, can be either MATLAB-data or an astra-identifier. +% proj_geom: MATLAB struct containing the projection geometry. +% vol_geom: MATLAB struct containing the volume geometry. +% sino_id: identifier of the sinogram data object as it is now stored in +% the astra-library. +% sino: MATLAB data version of the sinogram. +%-------------------------------------------------------------------------- +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + + +% store volume +if (numel(data) > 1) + volume_id = astra_mex_data3d('create','-vol', vol_geom, data); +else + volume_id = data; +end + +% store sino +sino_id = astra_mex_data3d('create','-sino', proj_geom, 0); + +% create sinogram +cfg = astra_struct('FP3D_CUDA'); +cfg.ProjectionDataId = sino_id; +cfg.VolumeDataId = volume_id; +alg_id = astra_mex_algorithm('create', cfg); +astra_mex_algorithm('iterate', alg_id); +astra_mex_algorithm('delete', alg_id); + +if (numel(data) > 1) + astra_mex_data3d('delete', volume_id); +end + +if nargout >= 2 + sino = astra_mex_data3d('get',sino_id); +end + + + diff --git a/matlab/tools/astra_create_sino_cuda.m b/matlab/tools/astra_create_sino_cuda.m new file mode 100644 index 0000000..82bda7c --- /dev/null +++ b/matlab/tools/astra_create_sino_cuda.m @@ -0,0 +1,58 @@ +function [sino_id, sino] = astra_create_sino_cuda(data, proj_geom, vol_geom, gpu_index) + +%-------------------------------------------------------------------------- +% [sino_id, sino] = astra_create_sino_cuda(data, proj_geom, vol_geom, gpu_index) +% +% Create a GPU based forward projection. +% +% data: input volume, can be either MATLAB-data or an astra-identifier. +% proj_geom: MATLAB struct containing the projection geometry. +% vol_geom: MATLAB struct containing the volume geometry. +% gpu_index: the index of the GPU to use (optional). +% sino_id: identifier of the sinogram data object as it is now stored in +% the astra-library. +% sino: MATLAB data version of the sinogram. +%-------------------------------------------------------------------------- +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + + +% store volume +if (numel(data) > 1) + volume_id = astra_mex_data2d('create','-vol', vol_geom, data); +else + volume_id = data; +end + +% store sino +sino_id = astra_mex_data2d('create','-sino', proj_geom, 0); + +% create sinogram +cfg = astra_struct('FP_CUDA'); +cfg.ProjectionDataId = sino_id; +cfg.VolumeDataId = volume_id; +if nargin > 3 + cfg.option.GPUindex = gpu_index; +end +alg_id = astra_mex_algorithm('create', cfg); +astra_mex_algorithm('iterate', alg_id); +astra_mex_algorithm('delete', alg_id); + +if (numel(data) > 1) + astra_mex_data2d('delete', volume_id); +end + +if nargout >= 2 + sino = astra_mex_data2d('get',sino_id); +end + + + diff --git a/matlab/tools/astra_create_sino_gpu.m b/matlab/tools/astra_create_sino_gpu.m new file mode 100644 index 0000000..95a3b09 --- /dev/null +++ b/matlab/tools/astra_create_sino_gpu.m @@ -0,0 +1,58 @@ +function [sino_id, sino] = astra_create_sino_gpu(data, proj_geom, vol_geom, gpu_index) + +%-------------------------------------------------------------------------- +% [sino_id, sino] = astra_create_sino_gpu(data, proj_geom, vol_geom, gpu_index) +% +% Create a GPU based forward projection. +% +% data: input volume, can be either MATLAB-data or an astra-identifier. +% proj_geom: MATLAB struct containing the projection geometry. +% vol_geom: MATLAB struct containing the volume geometry. +% gpu_index: the index of the GPU to use (optional). +% sino_id: identifier of the sinogram data object as it is now stored in +% the astra-library. +% sino: MATLAB data version of the sinogram. +%-------------------------------------------------------------------------- +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + + +% store volume +if (numel(data) > 1) + volume_id = astra_mex_data2d('create','-vol', vol_geom, data); +else + volume_id = data; +end + +% store sino +sino_id = astra_mex_data2d('create','-sino', proj_geom, 0); + +% create sinogram +cfg = astra_struct('FP_CUDA'); +cfg.ProjectionDataId = sino_id; +cfg.VolumeDataId = volume_id; +if nargin > 3 + cfg.option.GPUindex = gpu_index; +end +alg_id = astra_mex_algorithm('create', cfg); +astra_mex_algorithm('iterate', alg_id); +astra_mex_algorithm('delete', alg_id); + +if (numel(data) > 1) + astra_mex_data2d('delete', volume_id); +end + +if nargout >= 2 + sino = astra_mex_data2d('get',sino_id); +end + + + diff --git a/matlab/tools/astra_create_sino_sampling.m b/matlab/tools/astra_create_sino_sampling.m new file mode 100644 index 0000000..6b86d61 --- /dev/null +++ b/matlab/tools/astra_create_sino_sampling.m @@ -0,0 +1,59 @@ +function [sino_id, sino] = astra_create_sino_sampling(data, proj_geom, vol_geom, gpu_index, sampling) + +%-------------------------------------------------------------------------- +% [sino_id, sino] = astra_create_sino_cuda(data, proj_geom, vol_geom, gpu_index) +% +% Create a GPU based forward projection. +% +% data: input volume, can be either MATLAB-data or an astra-identifier. +% proj_geom: MATLAB struct containing the projection geometry. +% vol_geom: MATLAB struct containing the volume geometry. +% gpu_index: the index of the GPU to use (optional). +% sino_id: identifier of the sinogram data object as it is now stored in +% the astra-library. +% sino: MATLAB data version of the sinogram. +%-------------------------------------------------------------------------- +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + + +% store volume +if (numel(data) > 1) + volume_id = astra_mex_data2d('create','-vol', vol_geom, data); +else + volume_id = data; +end + +% store sino +sino_id = astra_mex_data2d('create','-sino', proj_geom, 0); + +% create sinogram +cfg = astra_struct('FP_CUDA'); +cfg.ProjectionDataId = sino_id; +cfg.VolumeDataId = volume_id; +cfg.option.DetectorSuperSampling = sampling; +if nargin > 3 + cfg.option.GPUindex = gpu_index; +end +alg_id = astra_mex_algorithm('create', cfg); +astra_mex_algorithm('iterate', alg_id); +astra_mex_algorithm('delete', alg_id); + +if (numel(data) > 1) + astra_mex_data2d('delete', volume_id); +end + +if nargout >= 2 + sino = astra_mex_data2d('get',sino_id); +end + + + diff --git a/matlab/tools/astra_create_vol_geom.m b/matlab/tools/astra_create_vol_geom.m new file mode 100644 index 0000000..61db8fb --- /dev/null +++ b/matlab/tools/astra_create_vol_geom.m @@ -0,0 +1,96 @@ +function vol_geom = astra_create_vol_geom(varargin) + +%-------------------------------------------------------------------------- +% vol_geom = astra_create_vol_geom([row_count col_count]); +% vol_geom = astra_create_vol_geom(row_count, col_count); +% vol_geom = astra_create_vol_geom(row_count, col_count, min_x, max_x, min_y, max_y); +% +% Create a 2D volume geometry. See the API for more information. +% row_count: number of rows. +% col_count: number of columns. +% min_x: minimum value on the x-axis. +% max_x: maximum value on the x-axis. +% min_y: minimum value on the y-axis. +% max_y: maximum value on the y-axis. +% vol_geom: MATLAB struct containing all information of the geometry. +%-------------------------------------------------------------------------- +% vol_geom = astra_create_vol_geom(row_count, col_count, slice_count); +% +% Create a 3D volume geometry. See the API for more information. +% row_count: number of rows. +% col_count: number of columns. +% slice_count: number of slices. +% vol_geom: MATLAB struct containing all information of the geometry. +%-------------------------------------------------------------------------- +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + +% astra_create_vol_geom([row_and_col_count ]) +if numel(varargin) == 1 && numel(varargin{1}) == 1 + vol_geom = struct(); + vol_geom.GridRowCount = varargin{1}(1); + vol_geom.GridColCount = varargin{1}(1); + vol_geom.option.WindowMinX = -varargin{1}(1) / 2; + vol_geom.option.WindowMaxX = varargin{1}(1) / 2; + vol_geom.option.WindowMinY = -varargin{1}(1) / 2; + vol_geom.option.WindowMaxY = varargin{1}(1) / 2; + + +% astra_create_vol_geom([row_count col_count]) +elseif numel(varargin) == 1 && numel(varargin{1}) == 2 + vol_geom = struct(); + vol_geom.GridRowCount = varargin{1}(1); + vol_geom.GridColCount = varargin{1}(2); + vol_geom.option.WindowMinX = -varargin{1}(2) / 2; + vol_geom.option.WindowMaxX = varargin{1}(2) / 2; + vol_geom.option.WindowMinY = -varargin{1}(1) / 2; + vol_geom.option.WindowMaxY = varargin{1}(1) / 2; + +% astra_create_vol_geom([row_count col_count slice_count]) +elseif numel(varargin) == 1 && numel(varargin{1}) == 3 + vol_geom = struct(); + vol_geom.GridRowCount = varargin{1}(1); + vol_geom.GridColCount = varargin{1}(2); + vol_geom.GridSliceCount = varargin{1}(3); + vol_geom.option.WindowMinX = -varargin{1}(2) / 2; + vol_geom.option.WindowMaxX = varargin{1}(2) / 2; + vol_geom.option.WindowMinY = -varargin{1}(1) / 2; + vol_geom.option.WindowMaxY = varargin{1}(1) / 2; + vol_geom.option.WindowMinZ = -varargin{1}(3) / 2; + vol_geom.option.WindowMaxZ = varargin{1}(3) / 2; + +% astra_create_vol_geom(row_count, col_count) +elseif numel(varargin) == 2 + vol_geom = struct(); + vol_geom.GridRowCount = varargin{1}; + vol_geom.GridColCount = varargin{2}; + vol_geom.option.WindowMinX = -varargin{2} / 2; + vol_geom.option.WindowMaxX = varargin{2} / 2; + vol_geom.option.WindowMinY = -varargin{1} / 2; + vol_geom.option.WindowMaxY = varargin{1} / 2; + +% astra_create_vol_geom(row_count, col_count, min_x, max_x, min_y, max_y) +elseif numel(varargin) == 6 + vol_geom = struct(); + vol_geom.GridRowCount = varargin{1}; + vol_geom.GridColCount = varargin{2}; + vol_geom.option.WindowMinX = varargin{3}; + vol_geom.option.WindowMaxX = varargin{4}; + vol_geom.option.WindowMinY = varargin{5}; + vol_geom.option.WindowMaxY = varargin{6}; + +% astra_create_vol_geom(row_count, col_count, slice_count) +elseif numel(varargin) == 3 + vol_geom = struct(); + vol_geom.GridRowCount = varargin{1}; + vol_geom.GridColCount = varargin{2}; + vol_geom.GridSliceCount = varargin{3}; +end diff --git a/matlab/tools/astra_data_gui.fig b/matlab/tools/astra_data_gui.fig Binary files differnew file mode 100644 index 0000000..d73e430 --- /dev/null +++ b/matlab/tools/astra_data_gui.fig diff --git a/matlab/tools/astra_data_gui.m b/matlab/tools/astra_data_gui.m new file mode 100644 index 0000000..337a5d4 --- /dev/null +++ b/matlab/tools/astra_data_gui.m @@ -0,0 +1,396 @@ +function varargout = astra_data_gui(varargin) +% ASTRA_DATA_GUI M-file for ASTRA_DATA_GUI.fig +% ASTRA_DATA_GUI, by itself, creates a new ASTRA_DATA_GUI or raises the existing +% singleton*. +% +% H = ASTRA_DATA_GUI returns the handle to a new ASTRA_DATA_GUI or the handle to +% the existing singleton*. +% +% ASTRA_DATA_GUI('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in ASTRA_DATA_GUI.M with the given input arguments. +% +% ASTRA_DATA_GUI('Property','Value',...) creates a new ASTRA_DATA_GUI or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the GUI before ASTRA_DATA_GUI_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to ASTRA_DATA_GUI_OpeningFcn via varargin. +% +% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one +% instance to run (singleton)". +% +% See also: GUIDE, GUIDATA, GUIHANDLES + +% Edit the above text to modify the response to help ASTRA_DATA_GUI + +% Last Modified by GUIDE v2.5 05-Mar-2012 14:34:03 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @astra_data_gui_OpeningFcn, ... + 'gui_OutputFcn', @astra_data_gui_OutputFcn, ... + 'gui_LayoutFcn', [] , ... + 'gui_Callback', []); +if nargin && ischar(varargin{1}) + gui_State.gui_Callback = str2func(varargin{1}); +end + +if nargout + [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); +else + gui_mainfcn(gui_State, varargin{:}); +end +% End initialization code - DO NOT EDIT + + +% --- Executes just before astra_data_gui is made visible. +function astra_data_gui_OpeningFcn(hObject, eventdata, handles, varargin) +% This function has no output args, see OutputFcn. +% hObject handle to figure +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +% varargin command line arguments to astra_data_gui (see VARARGIN) + +% Choose default command line output for astra_data_gui +handles.output = hObject; +handles.data = []; + +% Update handles structure +guidata(hObject, handles); + +% UIWAIT makes astra_data_gui wait for user response (see UIRESUME) +% uiwait(handles.figure1); + + +% --- Outputs from this function are returned to the command line. +function varargout = astra_data_gui_OutputFcn(hObject, eventdata, handles) +% varargout cell array for returning output args (see VARARGOUT); +% hObject handle to figure +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Get default command line output from handles structure +varargout{1} = handles.output; + + +% Use this function to display a figure using the gui from any m-file +% example: +% Handle = astra_data_gui(); +% astra_data_gui('loadVolume',guihandles(Handle),'rand(30,30,30)',15); +function loadVolume(handles,name,figure_number) +set(handles.txt_var, 'String', name); +set(handles.figure_number, 'String', num2str(figure_number)); +btn_load_Callback(handles.txt_var, [], handles); + + + + + +function txt_var_Callback(hObject, eventdata, handles) %#ok<*DEFNU> +% hObject handle to txt_var (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'String') returns contents of txt_var as text +% str2double(get(hObject,'String')) returns contents of txt_var as a double + + +% --- Executes during object creation, after setting all properties. +function txt_var_CreateFcn(hObject, eventdata, handles) +% hObject handle to txt_var (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: edit controls usually have a white background on Windows. +% See ISPC and COMPUTER. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + +% --- Executes on button press in btn_load. +function btn_load_Callback(hObject, eventdata, handles) +% hObject handle to btn_load (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +s = get(handles.txt_var, 'String'); +data = evalin('base', s); +handles.data = data; +guidata(hObject, handles); + +% Set Default Stuff +set(handles.sld_slice, 'Min',1); +set(handles.sld_slice, 'Max', size(data,3)); +set(handles.sld_slice, 'SliderStep', [1/(size(data,3)-2) 1/(size(data,3)-2)]); +set(handles.sld_slice, 'Value', size(data,3)/2); + +sliderValue = floor(get(handles.sld_slice, 'Value')); +set(handles.txt_slice, 'String', num2str(sliderValue)); +set(handles.txt_min, 'String', num2str(1)); +set(handles.txt_max, 'String', num2str(size(data,3))); + +set(handles.sld_magnification, 'Min',1); +set(handles.sld_magnification, 'Max', 400); +set(handles.sld_magnification, 'SliderStep', [1/(400-2) 1/(400-2)]); +set(handles.sld_magnification, 'Value', 100); + +sliderValue3 = floor(get(handles.sld_magnification, 'Value')); +set(handles.txt_mag, 'String', num2str(sliderValue3)); + + +figure_number = floor(str2double(get(handles.figure_number, 'String'))); +if(isnan(figure_number) || figure_number < 1) + set(handles.figure_number, 'String', num2str(10)); +end + +showimage(handles); + +% --- SHOW IMAGE +function showimage(handles) + sliderValue = floor(get(handles.sld_slice, 'Value')); + magnification = floor(get(handles.sld_magnification, 'Value')); + figure_number = floor(str2double(get(handles.figure_number, 'String'))); + image_matrix = handles.data; + if get(handles.btn_x, 'Value') == 1 + figure(figure_number), imshow(sliceExtractor((image_matrix(:,:,:)), 'y', sliderValue),[],'InitialMagnification', magnification); + ylabel('y') + xlabel('z') + set(gcf,'Name','ASTRA DATA GUI') + elseif get(handles.btn_y, 'Value') == 1 + figure(figure_number), imshow(sliceExtractor((image_matrix(:,:,:)), 'x', sliderValue),[],'InitialMagnification', magnification); + ylabel('x') + xlabel('z') + set(gcf,'Name','ASTRA DATA GUI') + else + figure(figure_number), imshow(sliceExtractor((image_matrix(:,:,:)), 'z', sliderValue),[],'InitialMagnification', magnification); + ylabel('x') + xlabel('y') + set(gcf,'Name','ASTRA DATA GUI') + end + + +% --- Executes on slider movement. +function sld_slice_Callback(hObject, eventdata, handles) +% hObject handle to sld_slice (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +sliderValue = floor(get(handles.sld_slice, 'Value')); +set(handles.txt_slice, 'String', num2str(sliderValue)); +showimage(handles); + +% --- Executes during object creation, after setting all properties. +function sld_slice_CreateFcn(hObject, eventdata, handles) +% hObject handle to sld_slice (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: slider controls usually have a light gray background. +if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor',[.9 .9 .9]); +end + + +% --- Executes on button press in pushbutton2. +function pushbutton2_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton2 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + + +% --- Executes on button press in pushbutton3. +function pushbutton3_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton3 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + + +% --- Executes on button press in pushbutton4. +function pushbutton4_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton4 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + + +function txt_slice_Callback(hObject, eventdata, handles) +% hObject handle to txt_slice (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +slice = str2double(get(handles.txt_slice, 'String')); +max = str2num(get(handles.txt_max,'String')); +min = str2num(get(handles.txt_min,'String')); +if(slice > max) + set(handles.txt_slice, 'String', num2str(max)); + set(handles.sld_slice, 'Value', max); +elseif(slice < min) + set(handles.txt_slice, 'String', num2str(min)); + set(handles.sld_slice, 'Value', min); +else + set(handles.sld_slice, 'Value', slice); +end +showimage(handles); + +% --- Executes during object creation, after setting all properties. +function txt_slice_CreateFcn(hObject, eventdata, handles) +% hObject handle to txt_slice (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: edit controls usually have a white background on Windows. +% See ISPC and COMPUTER. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + +% --- Executes on slider movement. +function sld_magnification_Callback(hObject, eventdata, handles) +% hObject handle to sld_slice2 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'Value') returns position of slider +% get(hObject,'Min') and get(hObject,'Max') to determine range of slider +sliderValue3 = floor(get(handles.sld_magnification, 'Value')); +set(handles.txt_mag, 'String', num2str(sliderValue3)); + +if(~isempty(handles.data)) + showimage(handles); +end + + + +% --- Executes during object creation, after setting all properties. +function sld_magnification_CreateFcn(hObject, eventdata, handles) +% hObject handle to sld_slice2 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called +% Hint: slider controls usually have a light gray background. +if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor',[.9 .9 .9]); +end + + +function txt_mag_Callback(hObject, eventdata, handles) +% hObject handle to txt_slice2 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +magnification = str2double(get(handles.txt_mag, 'String')); +if(magnification > 400) + set(handles.txt_mag, 'String', num2str(400)); + set(handles.sld_magnification, 'Value', 400); +elseif(magnification < 1) + set(handles.txt_mag, 'String', num2str(1)); + set(handles.sld_magnification, 'Value', 1); +else + set(handles.sld_magnification, 'Value', magnification); +end + +if(~isempty(handles.data)) + showimage(handles); +end + +% --- Executes during object creation, after setting all properties. +function txt_mag_CreateFcn(hObject, eventdata, handles) +% hObject handle to txt_slice2 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: edit controls usually have a white background on Windows. +% See ISPC and COMPUTER. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + +% --- Executes on slider movement. +function figure_number_Callback(hObject, eventdata, handles) +% hObject handle to sld_slice2 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'Value') returns position of slider +% get(hObject,'Min') and get(hObject,'Max') to determine range of slider +number = floor(str2double(get(handles.figure_number, 'String'))); +if(number < 1) + set(handles.figure_number, 'String', num2str(1)); +else + set(handles.figure_number, 'String', num2str(number)); +end + +if(~isempty(handles.data)) + showimage(handles); +end + + +% --- Executes during object creation, after setting all properties. +function figure_number_CreateFcn(hObject, eventdata, handles) +% hObject handle to sld_slice2 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called +% Hint: slider controls usually have a light gray background. +if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor',[.9 .9 .9]); +end + + + +% --- Executes when selected object is changed in btn_dir. +function btn_dir_SelectionChangeFcn(hObject, eventdata, handles) +% hObject handle to the selected object in btn_dir +% eventdata structure with the following fields (see UIBUTTONGROUP) +% EventName: string 'SelectionChanged' (read only) +% OldValue: handle of the previously selected object or empty if none was selected +% NewValue: handle of the currently selected object +% handles structure with handles and user data (see GUIDATA) + +data = handles.data; + +if(hObject == handles.btn_x) + set(handles.btn_x, 'Value', 1); + set(handles.btn_y, 'Value', 0); + set(handles.btn_z, 'Value', 0); +elseif(hObject == handles.btn_y) + set(handles.btn_x, 'Value', 0); + set(handles.btn_y, 'Value', 1); + set(handles.btn_z, 'Value', 0); +elseif(hObject == handles.btn_z) + set(handles.btn_x, 'Value', 0); + set(handles.btn_y, 'Value', 0); + set(handles.btn_z, 'Value', 1); +end + +if get(handles.btn_x, 'Value') == 1 + set(handles.sld_slice, 'Min',1); + set(handles.sld_slice, 'Max', size(data,1)); + set(handles.sld_slice, 'SliderStep', [1/(size(data,1)-2) 1/(size(data,1)-2)]); + set(handles.sld_slice, 'Value', size(data,1)/2); + + sliderValue = get(handles.sld_slice, 'Value'); + set(handles.txt_slice, 'String', num2str(sliderValue)); + set(handles.txt_min, 'String', num2str(1)); + set(handles.txt_max, 'String', num2str(size(data,1))); + +elseif get(handles.btn_y, 'Value') == 1 + set(handles.sld_slice, 'Min',1); + set(handles.sld_slice, 'Max', size(data,2)); + set(handles.sld_slice, 'SliderStep', [1/(size(data,2)-2) 1/(size(data,2)-2)]); + set(handles.sld_slice, 'Value', size(data,2)/2); + + sliderValue = get(handles.sld_slice, 'Value'); + set(handles.txt_slice, 'String', num2str(sliderValue)); + set(handles.txt_min, 'String', num2str(1)); + set(handles.txt_max, 'String', num2str(size(data,2))); +else + set(handles.sld_slice, 'Min',1); + set(handles.sld_slice, 'Max', size(data,3)); + set(handles.sld_slice, 'SliderStep', [1/(size(data,3)-2) 1/(size(data,3)-2)]); + set(handles.sld_slice, 'Value', size(data,3)/2); + + sliderValue = get(handles.sld_slice, 'Value'); + set(handles.txt_slice, 'String', num2str(sliderValue)); + set(handles.txt_min, 'String', num2str(1)); + set(handles.txt_max, 'String', num2str(size(data,3))); +end + +showimage(handles); diff --git a/matlab/tools/astra_data_op.m b/matlab/tools/astra_data_op.m new file mode 100644 index 0000000..b6ef0e2 --- /dev/null +++ b/matlab/tools/astra_data_op.m @@ -0,0 +1,11 @@ +function astra_data_op(op, data, scalar, gpu_core) + +cfg = astra_struct('DataOperation_CUDA'); +cfg.Operation = op; +cfg.Scalar = scalar; +cfg.DataId = data; +cfg.option.GPUindex = gpu_core; + +alg_id = astra_mex_algorithm('create',cfg); +astra_mex_algorithm('run',alg_id); +astra_mex_algorithm('delete',alg_id);
\ No newline at end of file diff --git a/matlab/tools/astra_data_op_mask.m b/matlab/tools/astra_data_op_mask.m new file mode 100644 index 0000000..d46c925 --- /dev/null +++ b/matlab/tools/astra_data_op_mask.m @@ -0,0 +1,12 @@ +function astra_data_op_mask(op, data, scalar, mask, gpu_core) + +cfg = astra_struct('DataOperation_CUDA'); +cfg.Operation = op; +cfg.Scalar = scalar; +cfg.DataId = data; +cfg.option.GPUindex = gpu_core; +cfg.option.MaskId = mask; + +alg_id = astra_mex_algorithm('create',cfg); +astra_mex_algorithm('run',alg_id); +astra_mex_algorithm('delete',alg_id);
\ No newline at end of file diff --git a/matlab/tools/astra_downsample_sinogram.m b/matlab/tools/astra_downsample_sinogram.m new file mode 100644 index 0000000..30c1cdd --- /dev/null +++ b/matlab/tools/astra_downsample_sinogram.m @@ -0,0 +1,36 @@ +function [sinogram_new, proj_geom_new] = astra_downsample_sinogram(sinogram, proj_geom, factor) + +%------------------------------------------------------------------------ +% [sinogram_new, proj_geom_new] = astra_downsample_sinogram(sinogram, proj_geom, factor) +% +% Downsample the sinogram with some factor and adjust projection geometry +% accordingly +% +% sinogram: MATLAB data version of the sinogram. +% proj_geom: MATLAB struct containing the projection geometry. +% factor: the factor by which the number of detectors is divided. +% sinogram_new: MATLAB data version of the resampled sinogram. +% proj_geom_new: MATLAB struct containing the new projection geometry. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + +if mod(size(sinogram,2),factor) ~= 0 + disp('size of the sinogram must be a divisor of the factor'); +end + +sinogram_new = zeros(size(sinogram,1),size(sinogram,2)/factor); +for i = 1:size(sinogram,2)/factor + sinogram_new(:,i) = sum(sinogram(:,(factor*(i-1)+1):factor*i),2); +end + +proj_geom_new = proj_geom; +proj_geom_new.DetectorCount = proj_geom_new.DetectorCount / factor; diff --git a/matlab/tools/astra_geom_2vec.m b/matlab/tools/astra_geom_2vec.m new file mode 100644 index 0000000..0abd07c --- /dev/null +++ b/matlab/tools/astra_geom_2vec.m @@ -0,0 +1,84 @@ +function proj_geom_out = astra_geom_2vec(proj_geom) + + % FANFLAT + if strcmp(proj_geom.type,'fanflat') + + vectors = zeros(numel(proj_geom.ProjectionAngles), 6); + for i = 1:numel(proj_geom.ProjectionAngles) + + % source + vectors(i,1) = sin(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginSource; + vectors(i,2) = -cos(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginSource; + + % center of detector + vectors(i,3) = -sin(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginDetector; + vectors(i,4) = cos(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginDetector; + + % vector from detector pixel 0 to 1 + vectors(i,5) = cos(proj_geom.ProjectionAngles(i)) * proj_geom.DetectorWidth; + vectors(i,6) = sin(proj_geom.ProjectionAngles(i)) * proj_geom.DetectorWidth; + end + + proj_geom_out = astra_create_proj_geom('fanflat_vec', proj_geom.DetectorCount, vectors); + + % CONE + elseif strcmp(proj_geom.type,'cone') + + vectors = zeros(numel(proj_geom.ProjectionAngles), 12); + for i = 1:numel(proj_geom.ProjectionAngles) + + % source + vectors(i,1) = sin(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginSource; + vectors(i,2) = -cos(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginSource; + vectors(i,3) = 0; + + % center of detector + vectors(i,4) = -sin(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginDetector; + vectors(i,5) = cos(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginDetector; + vectors(i,6) = 0; + + % vector from detector pixel (0,0) to (0,1) + vectors(i,7) = cos(proj_geom.ProjectionAngles(i)) * proj_geom.DetectorSpacingX; + vectors(i,8) = sin(proj_geom.ProjectionAngles(i)) * proj_geom.DetectorSpacingX; + vectors(i,9) = 0; + + % vector from detector pixel (0,0) to (1,0) + vectors(i,10) = 0; + vectors(i,11) = 0; + vectors(i,12) = proj_geom.DetectorSpacingY; + end + + proj_geom_out = astra_create_proj_geom('cone_vec', proj_geom.DetectorRowCount, proj_geom.DetectorColCount, vectors); + + % PARALLEL + elseif strcmp(proj_geom.type,'parallel3d') + + vectors = zeros(numel(proj_geom.ProjectionAngles), 12); + for i = 1:numel(proj_geom.ProjectionAngles) + + % ray direction + vectors(i,1) = sin(proj_geom.ProjectionAngles(i)); + vectors(i,2) = -cos(proj_geom.ProjectionAngles(i)); + vectors(i,3) = 0; + + % center of detector + vectors(i,4) = 0; + vectors(i,5) = 0; + vectors(i,6) = 0; + + % vector from detector pixel (0,0) to (0,1) + vectors(i,7) = cos(proj_geom.ProjectionAngles(i)) * proj_geom.DetectorSpacingX; + vectors(i,8) = sin(proj_geom.ProjectionAngles(i)) * proj_geom.DetectorSpacingX; + vectors(i,9) = 0; + + % vector from detector pixel (0,0) to (1,0) + vectors(i,10) = 0; + vectors(i,11) = 0; + vectors(i,12) = proj_geom.DetectorSpacingY; + end + + proj_geom_out = astra_create_proj_geom('parallel3d_vec', proj_geom.DetectorRowCount, proj_geom.DetectorColCount, vectors); + + else + error(['No suitable vector geometry found for type: ' proj_geom.type]) + end diff --git a/matlab/tools/astra_geom_postalignment.m b/matlab/tools/astra_geom_postalignment.m new file mode 100644 index 0000000..4115af2 --- /dev/null +++ b/matlab/tools/astra_geom_postalignment.m @@ -0,0 +1,11 @@ +function proj_geom = astra_geom_postalignment(proj_geom, factor) + + if strcmp(proj_geom.type,'fanflat_vec') + proj_geom.Vectors(:,3:4) = proj_geom.Vectors(:,3:4) + factor * proj_geom.Vectors(:,5:6); + + elseif strcmp(proj_geom.type,'cone_vec') || strcmp(proj_geom.type,'parallel3d_vec') + proj_geom.Vectors(:,4:6) = proj_geom.Vectors(:,4:6) + factor * proj_geom.Vectors(:,7:9); + + else + error('Projection geometry not suited for postalignment correction.') + end diff --git a/matlab/tools/astra_geom_size.m b/matlab/tools/astra_geom_size.m new file mode 100644 index 0000000..c4956f5 --- /dev/null +++ b/matlab/tools/astra_geom_size.m @@ -0,0 +1,28 @@ +function s = astra_geom_size(geom, dim) + + if isfield(geom, 'GridSliceCount') + % 3D Volume geometry? + s = [ geom.GridColCount, geom.GridRowCount, geom.GridSliceCount ]; + elseif isfield(geom, 'GridColCount') + % 2D Volume geometry? + s = [ geom.GridRowCount, geom.GridColCount ]; + elseif strcmp(geom.type,'parallel') || strcmp(geom.type,'fanflat') + s = [numel(geom.ProjectionAngles), geom.DetectorCount]; + + elseif strcmp(geom.type,'parallel3d') || strcmp(geom.type,'cone') + s = [geom.DetectorRowCount, numel(geom.ProjectionAngles), geom.DetectorColCount]; + + elseif strcmp(geom.type,'fanflat_vec') + s = [size(geom.Vectors,1), geom.DetectorCount]; + + elseif strcmp(geom.type,'parallel3d_vec') || strcmp(geom.type,'cone_vec') + s = [geom.DetectorColCount, size(geom.Vectors,1), geom.DetectorRowCount]; + + end + + if nargin == 2 + s = s(dim); + end + +end + diff --git a/matlab/tools/astra_geom_superresolution.m b/matlab/tools/astra_geom_superresolution.m new file mode 100644 index 0000000..b2b0ebf --- /dev/null +++ b/matlab/tools/astra_geom_superresolution.m @@ -0,0 +1,14 @@ +function proj_geom = astra_geom_superresolution(proj_geom, factor) + + if strcmp(proj_geom.type,'parallel') + proj_geom.DetectorWidth = proj_geom.DetectorWidth/factor; + proj_geom.DetectorCount = proj_geom.DetectorCount * factor; + elseif strcmp(proj_geom.type,'fanflat') + proj_geom.DetectorWidth = proj_geom.DetectorWidth/factor; + proj_geom.DetectorCount = proj_geom.DetectorCount * factor; + elseif strcmp(proj_geom.type,'fanflat_vec') + proj_geom.Vectors(:,5:6) = proj_geom.Vectors(:,5:6) / factor; % DetectorSize + proj_geom.DetectorCount = proj_geom.DetectorCount * factor; + else + error('Projection geometry not suited for super-resolution (or not implemented).') + end diff --git a/matlab/tools/astra_imshow.m b/matlab/tools/astra_imshow.m new file mode 100644 index 0000000..6069674 --- /dev/null +++ b/matlab/tools/astra_imshow.m @@ -0,0 +1,10 @@ +function V = astra_imshow(data, range) + +if numel(data) == 1 + data = astra_mex_data2d('get', data); +end +imshow(data,range); + +if nargout >= 1 + V = data; +end
\ No newline at end of file diff --git a/matlab/tools/astra_mex.m b/matlab/tools/astra_mex.m new file mode 100644 index 0000000..e04cfea --- /dev/null +++ b/matlab/tools/astra_mex.m @@ -0,0 +1,24 @@ +function [varargout] = astra_mex(varargin) +%------------------------------------------------------------------------ +% Reference page in Help browser +% <a href="matlab:docsearch('astra_mex' )">astra_mex</a>. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ +if nargout == 0 + astra_mex_c(varargin{:}); + if exist('ans','var') + varargout{1} = ans; + end +else + varargout = cell(1,nargout); + [varargout{:}] = astra_mex_c(varargin{:}); +end diff --git a/matlab/tools/astra_mex_algorithm.m b/matlab/tools/astra_mex_algorithm.m new file mode 100644 index 0000000..138a43c --- /dev/null +++ b/matlab/tools/astra_mex_algorithm.m @@ -0,0 +1,24 @@ +function [varargout] = astra_mex_algorithm(varargin) +%------------------------------------------------------------------------ +% Reference page in Help browser +% <a href="matlab:docsearch('astra_mex_algorithm' )">astra_mex_algorithm</a>. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ +if nargout == 0 + astra_mex_algorithm_c(varargin{:}); + if exist('ans','var') + varargout{1} = ans; + end +else + varargout = cell(1,nargout); + [varargout{:}] = astra_mex_algorithm_c(varargin{:}); +end diff --git a/matlab/tools/astra_mex_data2d.m b/matlab/tools/astra_mex_data2d.m new file mode 100644 index 0000000..eacbcb9 --- /dev/null +++ b/matlab/tools/astra_mex_data2d.m @@ -0,0 +1,24 @@ +function [varargout] = astra_mex_data2d(varargin) +%------------------------------------------------------------------------ +% Reference page in Help browser +% <a href="matlab:docsearch('astra_mex_data2d' )">astra_mex_data2d</a>. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ +if nargout == 0 + astra_mex_data2d_c(varargin{:}); + if exist('ans','var') + varargout{1} = ans; + end +else + varargout = cell(1,nargout); + [varargout{:}] = astra_mex_data2d_c(varargin{:}); +end diff --git a/matlab/tools/astra_mex_data3d.m b/matlab/tools/astra_mex_data3d.m new file mode 100644 index 0000000..3bbbd68 --- /dev/null +++ b/matlab/tools/astra_mex_data3d.m @@ -0,0 +1,24 @@ +function [varargout] = astra_mex_data3d(varargin) +%------------------------------------------------------------------------ +% Reference page in Help browser +% <a href="matlab:docsearch('astra_mex_data3d' )">astra_mex_data3d</a>. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ +if nargout == 0 + astra_mex_data3d_c(varargin{:}); + if exist('ans','var') + varargout{1} = ans; + end +else + varargout = cell(1,nargout); + [varargout{:}] = astra_mex_data3d_c(varargin{:}); +end diff --git a/matlab/tools/astra_mex_matrix.m b/matlab/tools/astra_mex_matrix.m new file mode 100644 index 0000000..182ab1e --- /dev/null +++ b/matlab/tools/astra_mex_matrix.m @@ -0,0 +1,24 @@ +function [varargout] = astra_mex_matrix(varargin) +%------------------------------------------------------------------------ +% Reference page in Help browser +% <a href="matlab:docsearch('astra_mex_matrix' )">astra_mex_matrix</a>. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ +if nargout == 0 + astra_mex_matrix_c(varargin{:}); + if exist('ans','var') + varargout{1} = ans; + end +else + varargout = cell(1,nargout); + [varargout{:}] = astra_mex_matrix_c(varargin{:}); +end diff --git a/matlab/tools/astra_mex_projector.m b/matlab/tools/astra_mex_projector.m new file mode 100644 index 0000000..487da06 --- /dev/null +++ b/matlab/tools/astra_mex_projector.m @@ -0,0 +1,24 @@ +function [varargout] = astra_mex_projector(varargin) +%------------------------------------------------------------------------ +% Reference page in Help browser +% <a href="matlab:docsearch('astra_mex_projector' )">astra_mex_projector</a>. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ +if nargout == 0 + astra_mex_projector_c(varargin{:}); + if exist('ans','var') + varargout{1} = ans; + end +else + varargout = cell(1,nargout); + [varargout{:}] = astra_mex_projector_c(varargin{:}); +end diff --git a/matlab/tools/astra_mex_projector3d.m b/matlab/tools/astra_mex_projector3d.m new file mode 100644 index 0000000..3d21ce9 --- /dev/null +++ b/matlab/tools/astra_mex_projector3d.m @@ -0,0 +1,24 @@ +function [varargout] = astra_mex_projector3d(varargin) +%------------------------------------------------------------------------ +% Reference page in Help browser +% <a href="matlab:docsearch('astra_mex_projector3d' )">astra_mex_projector3d</a>. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ +if nargout == 0 + astra_mex_projector3d_c(varargin{:}); + if exist('ans','var') + varargout{1} = ans; + end +else + varargout = cell(1,nargout); + [varargout{:}] = astra_mex_projector3d_c(varargin{:}); +end diff --git a/matlab/tools/astra_projector_handle.m b/matlab/tools/astra_projector_handle.m new file mode 100644 index 0000000..72d4c73 --- /dev/null +++ b/matlab/tools/astra_projector_handle.m @@ -0,0 +1,29 @@ +classdef astra_projector_handle < handle + %ASTRA_PROJECTOR_HANDLE Handle class around an astra_mex_projector id + % Automatically deletes the projector when deleted. + + %------------------------------------------------------------------------ + % This file is part of the + % All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") + % + % Copyright: iMinds-Vision Lab, University of Antwerp + % License: Open Source under GPLv3 + % Contact: mailto:astra@ua.ac.be + % Website: http://astra.ua.ac.be + %------------------------------------------------------------------------ + + properties + id + end + + methods + function obj = astra_projector_handle(proj_id) + obj.id = proj_id; + end + function delete(obj) + astra_mex_projector('delete', obj.id); + end + end + +end + diff --git a/matlab/tools/astra_set_directory.m b/matlab/tools/astra_set_directory.m new file mode 100644 index 0000000..1d5a368 --- /dev/null +++ b/matlab/tools/astra_set_directory.m @@ -0,0 +1,27 @@ +function in = astra_set_directory(in) + +%------------------------------------------------------------------------ +% in = astra_set_directory(in) +% +% Creates the directories present in the input path if they do not exist +% already +% +% in: input path. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + +a = find(in == '/' | in == '\'); +for i = 1:numel(a) + if ~isdir(in(1:a(i))) + mkdir(in(1:a(i))); + end +end diff --git a/matlab/tools/astra_struct.m b/matlab/tools/astra_struct.m new file mode 100644 index 0000000..f65b2ec --- /dev/null +++ b/matlab/tools/astra_struct.m @@ -0,0 +1,37 @@ +function res = astra_struct(type) + +%------------------------------------------------------------------------ +% res = astra_struct(type) +% +% Create an ASTRA struct +% +% type: type of the struct to be generated. +% res: the generated matlab struct. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ +res = struct(); +res.options = struct(); + + +if nargin >= 1 + % For backward compatibility, transparently accept SIRT_CUDA2 + % for SIRT_CUDA, and FP_CUDA2 for FP_CUDA. + if strcmp(type, 'SIRT_CUDA2') + type = 'SIRT_CUDA'; + warning('SIRT_CUDA2 has been deprecated. Use SIRT_CUDA instead.'); + end + if strcmp(type, 'FP_CUDA2') + type = 'FP_CUDA'; + warning('FP_CUDA2 has been deprecated. Use FP_CUDA instead.'); + end + res.type = type; +end diff --git a/matlab/tools/compute_rnmp.m b/matlab/tools/compute_rnmp.m new file mode 100644 index 0000000..6c00a01 --- /dev/null +++ b/matlab/tools/compute_rnmp.m @@ -0,0 +1,29 @@ +function [rnmp, nmp] = compute_rnmp(phantom, S) + + phantom = double(phantom == max(phantom(:))); + S = double(S == max(S(:))); + + %u1 = sort(unique(phantom)); + %u2 = sort(unique(S)); + %for i = 1:numel(u1) + % phantom_(phantom == u1(i)) = i; + % S_(S == u2(i)) = i; + %end + %phantom = phantom_; + %S = S_; + + if numel(size(phantom)) == 2 + S = imresize(S, size(phantom), 'nearest'); + elseif numel(size(phantom)) == 3 + S2 = zeros(size(phantom)); + for slice = 1:size(phantom,3) + S2(:,:,slice) = imresize(S(:,:,slice), [size(phantom,1) size(phantom,2)], 'nearest'); + end + S = S2; + end + + nmp = sum(abs(phantom(:) ~= S(:))); + rnmp = nmp / sum(phantom(:)); + +end + diff --git a/matlab/tools/createOrderART.m b/matlab/tools/createOrderART.m new file mode 100644 index 0000000..a469d8a --- /dev/null +++ b/matlab/tools/createOrderART.m @@ -0,0 +1,66 @@ +function rayOrder = createOrderART(proj_geom, mode) + +%------------------------------------------------------------------------ +% rayOrder = createOrderART(proj_geom, mode) +% +% Creates an array defining the order in which ART will iterate over the +% projections and projection rays +% +% proj_geom: MATLAB struct containing the projection geometry. +% mode: string defining the wanted ray order, can be either 'sequential', +% 'randomray' or 'randomproj'. +% rayOrder: array of two columns of length angle_count * det_count, with +% the first column being the index of the projection and the second column +% the index of the ray. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + +angle_count = length(proj_geom.projection_angles); +det_count = proj_geom.detector_count; + +% create order +rayOrder = zeros(angle_count * det_count, 2); +if strcmp(mode,'sequential') == 1 + index = 1; + for i = 1:angle_count + for j = 1:det_count + rayOrder(index,1) = i; + rayOrder(index,2) = j; + index = index + 1; + end + end +elseif strcmp(mode,'randomray') == 1 + index = 1; + for i = 1:angle_count + for j = 1:det_count + rayOrder(index,1) = i; + rayOrder(index,2) = j; + index = index + 1; + end + end + r = randperm(angle_count * det_count); + rayOrder(:,1) = rayOrder(r,1); + rayOrder(:,2) = rayOrder(r,2); +elseif strcmp(mode,'randomproj') == 1 + index = 1; + r = randperm(angle_count); + for i = 1:angle_count + for j = 1:det_count + rayOrder(index,1) = r(i); + rayOrder(index,2) = j; + index = index + 1; + end + end +else + disp('mode not known'); +end + diff --git a/matlab/tools/downsample_sinogram.m b/matlab/tools/downsample_sinogram.m new file mode 100644 index 0000000..1fb4ec8 --- /dev/null +++ b/matlab/tools/downsample_sinogram.m @@ -0,0 +1,12 @@ +function sinogram_out = downsample_sinogram(sinogram, ds) + + if ds == 1 + sinogram_out = sinogram; + return; + end + + sinogram_out = sinogram(:,1:ds:end,:); + for i = 2:ds + sinogram_out = sinogram_out + sinogram(:,i:ds:end,:); + end + sinogram_out = sinogram_out / (ds*ds);
\ No newline at end of file diff --git a/matlab/tools/imreadgs.m b/matlab/tools/imreadgs.m new file mode 100644 index 0000000..9c27eb4 --- /dev/null +++ b/matlab/tools/imreadgs.m @@ -0,0 +1,26 @@ +function Im = imreadgs(filename) + +%------------------------------------------------------------------------ +% Im = imreadgs(filename) +% +% Reads an image and transforms it into a grayscale image consisting of +% doubles. +% +% filename: name of the image file. +% Im: a grayscale image in double. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + +Im = double(imread(filename)); +if size(Im,3) > 1 + Im = Im(:,:,1); +end diff --git a/matlab/tools/imresize3D.m b/matlab/tools/imresize3D.m new file mode 100644 index 0000000..9032cc3 --- /dev/null +++ b/matlab/tools/imresize3D.m @@ -0,0 +1,26 @@ +function out = imresize3D(in, s_out, method) + +%------------------------------------------------------------------------ +% out = imresize3D(in, s_out, method) +% +% Resizes a 3-component image +% +% in: input image. +% s_out: 2 element array with the wanted image size, [rows columns]. +% out: the resized 3-component image. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + +out = zeros(s_out); +for i = 1:size(in,3) + out(:,:,i) = imresize(in(:,:,i), s_out(1:2), method); +end diff --git a/matlab/tools/imscale.m b/matlab/tools/imscale.m new file mode 100644 index 0000000..957f11f --- /dev/null +++ b/matlab/tools/imscale.m @@ -0,0 +1,28 @@ +function out = imscale(in) + +%------------------------------------------------------------------------ +% out = imscale(in) +% +% Rescales the image values between zero and one. +% +% in: input image. +% out: scaled output image. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + +mi = min(in(:)); +ma = max(in(:)); +if (ma-mi) == 0 + out = zeros(size(in)); +else + out = (in - mi) / (ma - mi); +end diff --git a/matlab/tools/imwritesc.m b/matlab/tools/imwritesc.m new file mode 100644 index 0000000..2f81dc8 --- /dev/null +++ b/matlab/tools/imwritesc.m @@ -0,0 +1,22 @@ +function imwritesc(in, filename) + +%------------------------------------------------------------------------ +% imwritesc(in, filename) +% +% Rescale between zero and one and write image +% +% in: input image. +% filename: name of output image file. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + +imwrite(imscale(in),filename); diff --git a/matlab/tools/kaiserBessel.m b/matlab/tools/kaiserBessel.m new file mode 100644 index 0000000..aef7b9d --- /dev/null +++ b/matlab/tools/kaiserBessel.m @@ -0,0 +1,31 @@ +function res = kaiserBessel(m,alpha,a,r) + +%------------------------------------------------------------------------ +% res = kaiserBessel(m,alpha,a,r) +% +% Calculates the Kaiser windowing function +% +% a: length of the sequence. +% m: order. +% alpha: determines shape of window. +% r: input values for which to compute window value. +% res: the window values. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + +sq = sqrt(1 - (r./a).^2); + +res1 = 1 ./ besseli(m, alpha); +res2 = sq .^ m; +res3 = besseli(m, alpha .* sq); + +res = res1 .* res2 .* res3; diff --git a/matlab/tools/linspace2.m b/matlab/tools/linspace2.m new file mode 100644 index 0000000..2787fd9 --- /dev/null +++ b/matlab/tools/linspace2.m @@ -0,0 +1,25 @@ +function out = linspace2(a,b,c) + +%------------------------------------------------------------------------ +% out = linspace2(a,b,c) +% +% Generates linearly spaced vectors +% +% a: lower limit. +% b: upper limit (exclusive). +% c: number of elements. +% out: linearly spaced vector. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + +out = linspace(a,b,c+1); +out = out(1:end-1); diff --git a/matlab/tools/overlayImage.m b/matlab/tools/overlayImage.m new file mode 100644 index 0000000..7c81e55 --- /dev/null +++ b/matlab/tools/overlayImage.m @@ -0,0 +1,24 @@ +function im = overlayImage(reconstruction, ground_truth) +%------------------------------------------------------------------------ +% im = overlayImage(reconstruction, ground_truth) +% +% Produces an overlay image of two images, useful for image comparison. +% +% reconstruction: first input image matrix. +% ground_truth: second input image matrix. +% im: output 3-component image, third channel is 0. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + +im(:,:,1) = reconstruction ./ max(reconstruction(:)); +im(:,:,2) = ground_truth ./ max(ground_truth(:)); +im(:,:,3) = zeros(size(reconstruction)); diff --git a/matlab/tools/rebin_fan2par.m b/matlab/tools/rebin_fan2par.m new file mode 100644 index 0000000..da20932 --- /dev/null +++ b/matlab/tools/rebin_fan2par.m @@ -0,0 +1,82 @@ +function F = rebin_fan2par(RadonData, BetaDeg, D, thetaDeg) + +%------------------------------------------------------------------------ +% F = rebin_fan2par(RadonData, BetaDeg, D, thetaDeg) +% +% Deze functie zet fan beam data om naar parallelle data, door interpolatie +% (fast resorting algorithm, zie Kak en Slaney) +% Radondata zoals altijd: eerste coord gamma , de rijen +% tweede coord beta, de kolommen, beide hoeken in +% radialen +% PixPProj: aantal pixels per projectie (voor skyscan data typisch 1000) +% BetaDeg: vector met alle draaihoeken in graden +% D: afstand bron - rotatiecentrum in pixels, dus afstand +% bron-rotatiecentrum(um) gedeeld door image pixel size (um). +% thetaDeg: vector met gewenste sinogramwaarden voor theta in graden +% de range van thetaDeg moet steeds kleiner zijn dan die van betadeg +% D,gamma,beta, theta zoals gebruikt in Kak & Slaney +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + +NpixPProj = size(RadonData,1); % aantal pixels per projectie +%if mod(size(Radondata,1),2)==0 +% NpixPProjNew=NpixPProj+1; +%else + NpixPProjNew = NpixPProj; +%end + +%% FAN-BEAM RAYS + +% flip sinogram, why? +RadonData = flipdim(RadonData,2); % matlab gebruikt tegengestelde draairichting (denkik) als skyscan, of er is een of andere flipdim geweest die gecorrigeerd moet worden)) + +% DetPixPos: distance of each detector to the ray through the origin (theta) +DetPixPos = -(NpixPProj-1)/2:(NpixPProj-1)/2; % posities detectorpixels + +% GammaStralen: alpha's? (result in radians!!) +GammaStralen = atan(DetPixPos/D); % alle met de detectorpixelposities overeenkomstige gammahoeken + +% put beta (theta) and gamma (alpha) for each ray in 2D matrices +[beta gamma] = meshgrid(BetaDeg,GammaStralen); + +% t: minimal distance between each ray and the ray through the origin +t = D*sin(gamma); % t-waarden overeenkomstig met de verschillende gamma's + +theta = gamma*180/pi + beta; % theta-waarden in graden overeenkomstig met verschillende gamma en beta waarden + +%% PARALLEL BEAM RAYS + +% DetPixPos: distance of each detector to the ray through the origin (theta) +DetPixPos = -(NpixPProjNew-1)/2:(NpixPProjNew-1)/2; % posities detectorpixels + +% GammaStralen: alpha's? (result in radians!!) +GammaStralenNew = atan(DetPixPos/D); % alle met de detectorpixelposities overeenkomstige gammahoeken + +% put beta (theta) and gamma (alpha) for each ray in 2D matrices +[~, gamma] = meshgrid(BetaDeg,GammaStralenNew); + +% t: minimal distance between each ray and the ray through the origin +tnew = D * sin(gamma); % t-waarden overeenkomstig met de verschillende gamma's + +% calculate new t +step = (max(tnew)-min(tnew)) / (NpixPProjNew-1); +t_para = min(tnew):step:max(tnew); + +[thetaNewCoord tNewCoord] = meshgrid(thetaDeg, t_para); + +%% Interpolate +Interpolant = TriScatteredInterp(theta(:), t(:), RadonData(:),'nearest'); +F = Interpolant(thetaNewCoord,tNewCoord); + + + + diff --git a/matlab/tools/sliceExtractor.m b/matlab/tools/sliceExtractor.m new file mode 100644 index 0000000..dfc87ee --- /dev/null +++ b/matlab/tools/sliceExtractor.m @@ -0,0 +1,34 @@ +function slice = sliceExtractor(data, dir, slicenr) + +%------------------------------------------------------------------------ +% slice = sliceExtractor(data, dir, slicenr) +% +% Outputs a specified slice from a three dimensional matrix/volume +% +% data: the 3D volume. +% dir: the direction in which the volume is sliced. +% slicenr: the index of the slice to retrieve. +% slice: 2D image matrix containing the slice. +%------------------------------------------------------------------------ +%------------------------------------------------------------------------ +% This file is part of the +% All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA-Toolbox") +% +% Copyright: iMinds-Vision Lab, University of Antwerp +% License: Open Source under GPLv3 +% Contact: mailto:astra@ua.ac.be +% Website: http://astra.ua.ac.be +%------------------------------------------------------------------------ +% $Id$ + +slicenr = round(slicenr); + +if strcmp(dir,'z') + slice = squeeze(data(:,:,slicenr)); +end +if strcmp(dir,'x') + slice = squeeze(data(:,slicenr,:)); +end +if strcmp(dir,'y') + slice = squeeze(data(slicenr,:,:)); +end |