[ITK] Resampling with streaming

livia.barazzetti at istb.unibe.ch livia.barazzetti at istb.unibe.ch
Sun Jan 10 13:34:50 EST 2016


Dear ITK members,

I'd like to use the IO streaming capabilities  of ITK  http://www.kitware.com/media/html/IOStreamingInITK.html for a simple pipeline: read mhd file, resample, write mhd file.
I tried different combination of input image size, output image size and number of streams, and it works with input data of 4GB.   But the program crashes trying to resample a 16G image into a 2G one(see log at the bottom). Is the problem in the  updatelargestregion /updateoutput information part?
Below the core of my program:

typedef signed short    PixelType;
const unsigned int      Dimension = 3;
typedef itk::Image<PixelType, Dimension> ImageType;

itk::OutputWindow::SetInstance(itk::TextOutput::New());
typedef itk::ImageFileReader<ImageType> ReaderType;
typedef itk::ImageFileWriter<ImageType> WriterType;

ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(inFileName);
reader->UpdateOutputInformation();

ImageType::Pointer input = reader->GetOutput();
std::cout << "Input size: " << input->GetLargestPossibleRegion().GetSize() << std::endl;

typedef itk::ResampleImageFilter< ImageType, ImageType > ResampleFilterType;
ResampleFilterType::Pointer resampleFilter = ResampleFilterType::New();

resampleFilter->SetInput( input );
resampleFilter->SetDefaultPixelValue(0);
resampleFilter->SetSize(outputSize);
resampleFilter->UpdateOutputInformation();
//resampleFilter->SetOutputSpacing( spacing ); //just for demo
std::cout << "Resampled image size: " << resampleFilter->GetOutput()->GetLargestPossibleRegion().GetSize() << std::endl;


typedef itk::PipelineMonitorImageFilter< ImageType > MonitorFilterType;
MonitorFilterType::Pointer monitorFilter = MonitorFilterType::New();
monitorFilter->SetInput(resampleFilter->GetOutput());
monitorFilter->DebugOn();

WriterType::Pointer outputWriter = WriterType::New();
outputWriter->SetFileName(outFileName);
outputWriter->SetInput(monitorFilter->GetOutput());
outputWriter->UseCompressionOff();
outputWriter->SetNumberOfStreamDivisions(nStreamDivisions);
outputWriter->Update();

And the error is:

Unhandled exception at 0x000007FEED1EA511 (msvcr110d.dll) in Resample.exe: 0xC0000005: Access violation writing location 0x00000002FA09B000.

               msvcr110d.dll!memcpy() Line 362            Unknown
>             msvcp110d.dll!std::char_traits<char>::copy(char * _First1, const char * _First2, unsigned __int64 _Count) Line 530                C++
               msvcp110d.dll!std::basic_streambuf<char,std::char_traits<char> >::xsgetn(char * _Ptr, __int64 _Count) Line 372                C++
               msvcp110d.dll!std::basic_streambuf<char,std::char_traits<char> >::sgetn(char * _Ptr, __int64 _Count) Line 160                C++
               msvcp110d.dll!std::basic_istream<char,std::char_traits<char> >::read(char * _Str, __int64 _Count) Line 742        C++
               Resample.exe!MetaImage::M_ReadElementData(std::basic_ifstream<char,std::char_traits<char> > * _fstream, void * _data, __int64 _dataQuantity) Line 3493  C++
               Resample.exe!MetaImage::M_ReadElements(std::basic_ifstream<char,std::char_traits<char> > * _fstream, void * _data, __int64 _dataQuantity) Line 2553               C++
               Resample.exe!MetaImage::ReadStream(int _nDims, std::basic_ifstream<char,std::char_traits<char> > * _stream, bool _readElements, void * _buffer) Line 1533  C++
               Resample.exe!MetaImage::Read(const char * _headerName, bool _readElements, void * _buffer) Line 1252    C++
               Resample.exe!itk::MetaImageIO::Read(void * buffer) Line 476 C++
               Resample.exe!itk::ImageFileReader<itk::Image<short,3>,itk::DefaultConvertPixelTraits<short> >::GenerateData() Line 448                C++
               Resample.exe!itk::ProcessObject::UpdateOutputData(itk::DataObject * __formal) Line 1739     C++
               Resample.exe!itk::DataObject::UpdateOutputData() Line 419    C++
               Resample.exe!itk::ImageBase<3>::UpdateOutputData() Line 291             C++
               Resample.exe!itk::ProcessObject::UpdateOutputData(itk::DataObject * __formal) Line 1711     C++
               Resample.exe!itk::DataObject::UpdateOutputData() Line 419    C++
               Resample.exe!itk::ImageBase<3>::UpdateOutputData() Line 291             C++
               Resample.exe!itk::ProcessObject::UpdateOutputData(itk::DataObject * __formal) Line 1703     C++
               Resample.exe!itk::DataObject::UpdateOutputData() Line 419    C++
               Resample.exe!itk::ImageBase<3>::UpdateOutputData() Line 291             C++
               Resample.exe!itk::ImageFileWriter<itk::Image<short,3> >::Write() Line 336        C++
               Resample.exe!itk::ImageFileWriter<itk::Image<short,3> >::Update() Line 166    C++
               Resample.exe!main(int argc, char * * argv) Line 96          C++
               Resample.exe!__tmainCRTStartup() Line 536     C
               Resample.exe!mainCRTStartup() Line 377            C
               kernel32.dll!0000000076ba5a4d()             Unknown
               ntdll.dll!0000000076cdb831()      Unknown
Thank you
Livia

Livia Barazzetti
Ph.D. Student - Medical Image Analysis
Institute for Surgical Technology and Biomechanics
University of Bern
Stauffacherstrasse 78
CH-3014 Bern
Tel +41 31 631 59 48
http://www.istb.unibe.ch<http://www.istb.unibe.ch/>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20160110/ef77f261/attachment.html>


More information about the Community mailing list