[ITK-dev] Streamed Read/Write Truncating Data

Maryana nexnaru at gmail.com
Mon Sep 21 14:54:37 EDT 2015


Hi ITK Users/Devs,

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?

Thank you!

#include <cstdlib>
#include <string>
#include <iostream>

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImageRegionIterator.h"
#include "itkNiftiImageIO.h"
#include "itkMetaImageIO.h"


int main(int argc, char const *argv[]){

  std::string fileIn = "brain_8bit.nii";
  std::string fileOut = "mri2_stream.mha";

  typedef itk::Image<unsigned char,3> Image3D;

 //Reader
  typedef itk::ImageFileReader<Image3D> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(fileIn);

 //Writer
  typedef itk::ImageFileWriter<Image3D> WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(fileOut);
  writer->SetNumberOfStreamDivisions(20);
  writer->SetInput(reader->GetOutput());


  std::cout << "Input: " << fileIn << std::endl;
  std::cout << "Output: " << fileOut << std::endl;

  std::cout << "Writing..." << std::endl;
  try
    {
      writer->Update();
    }
  catch( itk::ExceptionObject & err )
    {
      std::cerr << "ExceptionObject caught !" << std::endl;
      std::cerr << err << std::endl;
      return EXIT_FAILURE;
    }
  std::cout << "Finished." << std::endl;


  return EXIT_SUCCESS;
}





-- 
"Tudo no mundo começou com um sim. Uma molécula disse sim a outra molécula
e nasceu a vida" - Clarice Lispector
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-developers/attachments/20150921/adda02cd/attachment.html>


More information about the Insight-developers mailing list