<div dir="ltr">Dear ITK developers,<div><br></div><div>We think we have spotted a bug in the itkImageSeriesWriter which is causing a valgrind warning. The valgrind warning is the following:</div><div><br></div><div>====================</div>
<div><div>0xB3D961: itk::ImageIOBase::SetDirection(unsigned int, vnl_vector<double> const&) (itkImageIOBase.cxx:167)</div><div>0x680501: itk::ImageFileWriter<itk::Image<short, 2u> >::Write() (itkImageFileWriter.hxx:223)</div>
<div>0x67739A: itk::ImageFileWriter<itk::Image<short, 2u> >::Update() (itkImageFileWriter.h:166)</div><div>0x684673: itk::ImageSeriesWriter<itk::Image<float, 3u>, itk::Image<short, 2u> >::WriteFiles() (itkImageSeriesWriter.hxx:372)</div>
<div>0x684A44: itk::ImageSeriesWriter<itk::Image<float, 3u>, itk::Image<short, 2u> >::GenerateData() (itkImageSeriesWriter.hxx:178)</div><div>0x68A1D2: itk::ImageSeriesWriter<itk::Image<float, 3u>, itk::Image<short, 2u> >::Write() (itkImageSeriesWriter.hxx:105)</div>
<div>0x677178: itk::ImageSeriesWriter<itk::Image<float, 3u>, itk::Image<short, 2u> >::Update() (itkImageSeriesWriter.h:138)</div></div><div>====================<br></div><div><br></div><div>We are using ITK 4.5.</div>
<div><br></div><div>The code we use basically boils down to:</div><div><br></div><div>====================<br></div><div><div>// Create GDCM Image IO object.</div><div>typedef itk::GDCMImageIO ImageIOType;<br></div><div>ImageIOType::Pointer gdcm_io = ImageIOType::New();</div>
<div><br></div><div>// Set Image Type tag.</div><div>itk::MetaDataDictionary& dictionary = gdcm_io->GetMetaDataDictionary();</div><div>std::string tagkey, value;</div><div>tagkey = "0008|0008"; // Image Type</div>
<div>value = "DERIVED\\SECONDARY";</div><div>itk::EncapsulateMetaData<std::string>(dictionary, tagkey, value);</div><div><br></div><div>// Write DICOM series.<br></div><div>typename SeriesWriterType::Pointer writer = SeriesWriterType::New();</div>
<div>writer->SetInput(quantib_to_itk);</div><div>writer->SetImageIO(gdcm_io);</div><div>writer->SetFileNames(...filenames...);</div><div>writer->Update();</div></div><div>====================<br></div><div><br>
</div><div>We have tracked down the issue to the following:</div><div><br></div><div>As set the ImageIO object explicitly, the code at line 354 of itkImageSeriesWriter.hxx is executed:</div><div><br></div><div>====================<br>
</div><div>EncapsulateMetaData< unsigned int >(dictionary, ITK_NumberOfDimensions, inputImageDimension);<br></div><div>====================<br></div><div><br></div><div>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.</div>
<div><br></div><div>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.</div><div>-- <br></div><div>
<div dir="ltr"><font color="#000000"><span style="font-family:arial;font-size:small">Coert Metz, PhD</span></font><div><div dir="ltr"><div style="font-size:small;font-family:arial"><font color="#000000">Research & Development Engineer | <a href="http://www.quantib.com/" target="_blank">Quantib B.V.</a></font></div>
<div style="font-size:small;font-family:arial"><div><font color="#000000"><a href="mailto:c.metz@quantib.com" target="_blank">c.metz@quantib.com</a> | +31 650 68 60 28</font></div></div></div></div></div>
</div></div>
<br>
<font face="Arial, Helvetica, sans-serif" size="1" style="background-color:white">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.</font>