Commit d65598d5 authored by Simon Maretzke's avatar Simon Maretzke
Browse files

Ugly workaround to avoid crashes when reconstructing large volumes

parent bd728867
Pipeline #100821 passed with stage
in 1 minute and 29 seconds
......@@ -137,6 +137,12 @@ if isempty(settings.outputSize)
settings.outputSize = 2*floor(size(projs,2)/(2*sqrt(2)));
end
%% check usage
if numel(tomoAngles) ~= size(projs,3)
error('Number of tomographic angles does not match number of projections');
end
% Special case: complex-valued arrays are processed separately for real- imaginary parts
if ~isreal(projs)
vol = astraFDK(real(projs),tomoAngles,z01,z02,dx,settings) ...
......@@ -144,10 +150,30 @@ if ~isreal(projs)
return;
end
%% check usage
if numel(tomoAngles) ~= size(projs,3)
error('Number of tomographic angles does not match number of projections');
% WORKAROUND: Astra's FDK algorithm tends to cause crashes in MATLAB if the reconstructed volume
% is too large. In this case, the reconstruction has to be sequentially performed on smaller chunks
MAX_VOLUME_SIZE = 256*1024*1024; % Maximum 1 Gigabyte of volume data reconstructed in one chunk
numChunks = ceil(settings.outputSize.^2 * settings.numSlices / MAX_VOLUME_SIZE);
if numChunks > 1
vol = zeros([settings.outputSize*[1,1], settings.numSlices], 'single');
slicesPerChunk = ceil(settings.numSlices/numChunks);
for chunkIdx = 1:numChunks
firstSlice = 1+(chunkIdx-1)*slicesPerChunk;
lastSlice = min(firstSlice+slicesPerChunk-1, settings.numSlices);
midSlice = 0.5*(firstSlice+lastSlice);
settingsChunk = settings;
settingsChunk.numSlices = lastSlice - firstSlice + 1;
settingsChunk.offset = settings.offset + (midSlice-1) - (numSlices-1)/2;
vol(:,:,firstSlice:lastSlice) = astraFDK(projs, tomoAngles, z01, z02, dx, settingsChunk);
end
return;
end
%% here it starts
% create volume geometry
% input:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment