Skip to content

Commit

Permalink
BUG: Premature failure when reading dicom slices to 3D
Browse files Browse the repository at this point in the history
When reading individual 2D dicom slices, the slice thickness may not be
known at each slice reading.  If set to spacing of 0 (the default) an
exception is thrown before the inter-slice distance can be computed.

Catch this case and set a temporary inter-slice thickness.
  • Loading branch information
hjmjohnson committed Nov 17, 2024
1 parent 916a40c commit 296bed6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Modules/IO/GDCM/src/itkGDCMImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "gdcmDirectionCosines.h"

#include <fstream>
#include <itkImageBase.h>
#include <sstream>

namespace itk
Expand Down Expand Up @@ -681,7 +682,12 @@ GDCMImageIO::InternalReadImageInformation()
const double * sp = image.GetSpacing();
spacing[0] = sp[0];
spacing[1] = sp[1];
spacing[2] = sp[2];
// A 2D dicom slice may not have an explicit interslice provided per
// file. interslice distances can be computed after all slices are read.
// set to non-zero value here to avoid prematurely throwing an exception
// before the interslice thickness can be computed.
const auto abs_spacing_2 = std::abs(sp[2]); // Spacing may be negative at this point, will be fixed below
spacing[2] = (abs_spacing_2 < itk::DefaultImageCoordinateTolerance) ? 1.0 : sp[2];
}
break;
}
Expand Down

0 comments on commit 296bed6

Please sign in to comment.