Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Fix dicom reading slices #4955

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A 2D DICOM slice

file. Inter-slice distances (leave a single white space after the period)

Set to non-zero value

before the inter-slice

spacing[2] = (abs_spacing_2 < itk::DefaultImageCoordinateTolerance) ? 1.0 : sp[2];
}
break;
}
Expand Down
6 changes: 3 additions & 3 deletions Modules/IO/ImageBase/include/itkImageSeriesReader.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "itkMetaDataObject.h"
#include <cstddef> // For ptrdiff_t.
#include <iomanip>
#include "itkImageBase.h"

namespace itk
{
Expand Down Expand Up @@ -432,9 +433,8 @@ ImageSeriesReader<TOutputImage>::GenerateData()
SpacingScalarType dirNnorm = dirN.GetNorm();

if (this->m_SpacingDefined &&
!Math::AlmostEquals(
dirNnorm,
outputSpacing[this->m_NumberOfDimensionsInImage])) // either non-uniform sampling or missing slice
std::abs(dirNnorm - outputSpacing[this->m_NumberOfDimensionsInImage]) >
itk::DefaultImageCoordinateTolerance) // either non-uniform sampling or missing slice
{
nonUniformSampling = true;
spacingDeviation = itk::Math::abs(outputSpacing[this->m_NumberOfDimensionsInImage] - dirNnorm);
Expand Down
Loading