<div dir="ltr"><br clear="all"><div>Hi ITK Users/Devs,</div><div><br></div><div>I'm new to ITK and I need to write a small program to convert Nifti images to MetaIO. However, I need to use the streamed reader/writer because my image volumes can have several gigabytes. I was doing some tests with the following code but I've realized that whenever I use the stream I end up with a truncated volume. I'm using ITK 4.8. I'm sure my volume is of unsigned char type. Also, when I comment out the writer->SetNumberOfStreamDivisions(20); line I works fine. Does anyone knows what is wrong?</div><div><br></div><div>Thank you!</div><div><br></div><div><div>#include <cstdlib></div><div>#include <string></div><div>#include <iostream></div><div><br></div><div>#include "itkImage.h"</div><div>#include "itkImageFileReader.h"</div><div>#include "itkImageFileWriter.h"</div><div>#include "itkImageRegionIterator.h"</div><div>#include "itkNiftiImageIO.h"</div><div>#include "itkMetaImageIO.h"</div><div><br></div><div><br></div><div>int main(int argc, char const *argv[]){</div><div> </div><div> std::string fileIn = "brain_8bit.nii";</div><div> std::string fileOut = "mri2_stream.mha";</div><div> </div><div> typedef itk::Image<unsigned char,3> Image3D;</div><div> </div><div> //Reader</div><div> typedef itk::ImageFileReader<Image3D> ReaderType;</div><div> ReaderType::Pointer reader = ReaderType::New();</div><div> reader->SetFileName(fileIn);</div><div> </div><div> //Writer</div><div> typedef itk::ImageFileWriter<Image3D> WriterType;</div><div> WriterType::Pointer writer = WriterType::New();</div><div> writer->SetFileName(fileOut);</div><div> writer->SetNumberOfStreamDivisions(20);</div><div> writer->SetInput(reader->GetOutput());</div><div> </div><div> </div><div> std::cout << "Input: " << fileIn << std::endl;</div><div> std::cout << "Output: " << fileOut << std::endl;</div><div><br></div><div> std::cout << "Writing..." << std::endl;</div><div> try</div><div> {</div><div> writer->Update();</div><div> }</div><div> catch( itk::ExceptionObject & err )</div><div> {</div><div> std::cerr << "ExceptionObject caught !" << std::endl;</div><div> std::cerr << err << std::endl;</div><div> return EXIT_FAILURE;</div><div> }</div><div> std::cout << "Finished." << std::endl;</div><div> </div><div><br></div><div> return EXIT_SUCCESS;</div><div>}</div></div><div><br></div>
</div>