[ITK] Invalid read in itkImageIOBase.cxx:167 when setting ImageIO on itkSeriesWriter
Coert Metz
c.metz at quantib.com
Fri Apr 11 11:21:52 EDT 2014
Dear ITK developers,
We think we have spotted a bug in the itkImageSeriesWriter which is causing
a valgrind warning. The valgrind warning is the following:
====================
0xB3D961: itk::ImageIOBase::SetDirection(unsigned int, vnl_vector<double>
const&) (itkImageIOBase.cxx:167)
0x680501: itk::ImageFileWriter<itk::Image<short, 2u> >::Write()
(itkImageFileWriter.hxx:223)
0x67739A: itk::ImageFileWriter<itk::Image<short, 2u> >::Update()
(itkImageFileWriter.h:166)
0x684673: itk::ImageSeriesWriter<itk::Image<float, 3u>, itk::Image<short,
2u> >::WriteFiles() (itkImageSeriesWriter.hxx:372)
0x684A44: itk::ImageSeriesWriter<itk::Image<float, 3u>, itk::Image<short,
2u> >::GenerateData() (itkImageSeriesWriter.hxx:178)
0x68A1D2: itk::ImageSeriesWriter<itk::Image<float, 3u>, itk::Image<short,
2u> >::Write() (itkImageSeriesWriter.hxx:105)
0x677178: itk::ImageSeriesWriter<itk::Image<float, 3u>, itk::Image<short,
2u> >::Update() (itkImageSeriesWriter.h:138)
====================
We are using ITK 4.5.
The code we use basically boils down to:
====================
// Create GDCM Image IO object.
typedef itk::GDCMImageIO ImageIOType;
ImageIOType::Pointer gdcm_io = ImageIOType::New();
// Set Image Type tag.
itk::MetaDataDictionary& dictionary = gdcm_io->GetMetaDataDictionary();
std::string tagkey, value;
tagkey = "0008|0008"; // Image Type
value = "DERIVED\\SECONDARY";
itk::EncapsulateMetaData<std::string>(dictionary, tagkey, value);
// Write DICOM series.
typename SeriesWriterType::Pointer writer = SeriesWriterType::New();
writer->SetInput(quantib_to_itk);
writer->SetImageIO(gdcm_io);
writer->SetFileNames(...filenames...);
writer->Update();
====================
We have tracked down the issue to the following:
As set the ImageIO object explicitly, the code at line 354 of
itkImageSeriesWriter.hxx is executed:
====================
EncapsulateMetaData< unsigned int >(dictionary, ITK_NumberOfDimensions,
inputImageDimension);
====================
This explicitly sets the number of image dimensions of the dictionary input
image in the ImageIO instance. In this case we have a 3D image and write 2D
slices, so 3 will be set in the ImageIO instance dictionary and passed to
the itkImageFileWriter when writing the 2D slices. The itkImageFileWriter
reads the ITK_NumberOfDimensions tag from the dictionary to set the size
of, among others, the direction matrix (line 704 of itkGDCMImageIO.cxx).
This will in the end result in reading an invalid memory location in
itkImageIOBase at line 167, which loops over 3 dimensions while it should
loop over 2 dimensions. The code at line 356-368 also seems strange to me,
as the direction matrix should be 2x2, I think.
Maybe we are overlooking something, so I am curious if this is a real bug,
or that we maybe use the writer and the ImageIO object in the wrong way.
Curious for your insights.
--
Coert Metz, PhD
Research & Development Engineer | Quantib B.V. <http://www.quantib.com/>
c.metz at quantib.com | +31 650 68 60 28
--
This message may contain confidential or privileged information. If you are
not the addressee, please return the message to its sender and delete it
from your files.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140411/bc1a45d9/attachment.html>
More information about the Community
mailing list