Skip to content

Commit

Permalink
BUG: ImageSeriesWriter + GDCMImageIO loses info
Browse files Browse the repository at this point in the history
When directional cosines are copied from 3D volume to 2D slices by
ImageSeriesWriter, only the upper-left 2x2 matrix can be copied, due to the
dimension of m_Direction matrix.

Then GDCMImageIO sets zeros in the missing values of the first 2 lines of the
matrix.

This is not a problem if the directional cosines matrix is the identity matrix,
otherwise DICOM tag (0020,0037) Image Orientation (Patient) of the output
DICOM files is not valid.

ITK-281

Change-Id: I44bac496fb1132abb85a5f9d66bd7ad469c774b2
  • Loading branch information
hjmjohnson committed Jun 26, 2013
1 parent ec61e6e commit df66144
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Modules/IO/GDCM/src/itkGDCMImageIO.cxx
Expand Up @@ -708,6 +708,11 @@ void GDCMImageIO::Write(const void *buffer)
m_GlobalNumberOfDimensions = numberOfDimensions;
m_Origin.resize(m_GlobalNumberOfDimensions);
m_Spacing.resize(m_GlobalNumberOfDimensions);
m_Direction.resize(m_GlobalNumberOfDimensions);
for (unsigned int i = 0; i < m_GlobalNumberOfDimensions; i++)
{
m_Direction[i].resize(m_GlobalNumberOfDimensions);
}
}
else if ( key == ITK_Origin )
{
Expand All @@ -727,6 +732,19 @@ void GDCMImageIO::Write(const void *buffer)
m_Spacing[1] = spacingArray[1];
m_Spacing[2] = spacingArray[2];
}
else if( key == ITK_ZDirection )
{
typedef Matrix< double > DoubleMatrixType;
DoubleMatrixType directionMatrix;
ExposeMetaData< DoubleMatrixType >( dict, key, directionMatrix );
for(int i = 0; i<3; i++)
{
for(int j = 0; j<3; j++)
{
m_Direction[i][j]=directionMatrix[i][j];
}
}
}
else
{
itkDebugMacro(
Expand Down
1 change: 1 addition & 0 deletions Modules/IO/ImageBase/include/itkIOCommon.h
Expand Up @@ -69,6 +69,7 @@ extern ITK_EXPORT const char *const SPM_ROI_SCALE;
extern ITK_EXPORT const char *const ITK_FileNotes;
extern ITK_EXPORT const char *const ITK_Origin;
extern ITK_EXPORT const char *const ITK_Spacing;
extern ITK_EXPORT const char *const ITK_ZDirection;
extern ITK_EXPORT const char *const ITK_FileOriginator;
extern ITK_EXPORT const char *const ITK_OriginationDate;
extern ITK_EXPORT const char *const ITK_PatientID;
Expand Down
12 changes: 12 additions & 0 deletions Modules/IO/ImageBase/include/itkImageSeriesWriter.hxx
Expand Up @@ -352,6 +352,18 @@ ImageSeriesWriter< TInputImage, TOutputImage >
EncapsulateMetaData< DoubleArrayType >(dictionary, ITK_Origin, originArray);
EncapsulateMetaData< DoubleArrayType >(dictionary, ITK_Spacing, spacingArray);
EncapsulateMetaData< unsigned int >(dictionary, ITK_NumberOfDimensions, inputImageDimension);

typename InputImageType::DirectionType direction2 = inputImage->GetDirection();
typedef Matrix< double, inputImageDimension, inputImageDimension> DoubleMatrixType;
DoubleMatrixType directionMatrix;
for( unsigned int i = 0; i < inputImageDimension; i++ )
{
for( unsigned int j = 0; j < inputImageDimension; j++ )
{
directionMatrix[j][i] = direction2[i][j];
}
}
EncapsulateMetaData< DoubleMatrixType >( dictionary, ITK_ZDirection, directionMatrix );
}
}

Expand Down
1 change: 1 addition & 0 deletions Modules/IO/ImageBase/src/itkIOCommon.cxx
Expand Up @@ -27,6 +27,7 @@ const char *const SPM_ROI_SCALE = "SPM_ROI_SCALE";
const char *const ITK_FileNotes = "ITK_FileNotes";
const char *const ITK_Origin = "ITK_Origin";
const char *const ITK_Spacing = "ITK_Spacing";
const char *const ITK_ZDirection = "ITK_ZDirection";
const char *const ITK_FileOriginator = "ITK_FileOriginator";
const char *const ITK_OriginationDate = "ITK_OriginationDate";
const char *const ITK_PatientID = "ITK_PatientID";
Expand Down

0 comments on commit df66144

Please sign in to comment.