[ITK-dev] Streamed Read/Write Truncating Data

Bradley Lowekamp blowekamp at mail.nih.gov
Mon Sep 21 14:55:53 EDT 2015


Hello Maryana,

What compiler, platform and architecture are you compiling for?

Brad

On Sep 21, 2015, at 2:54 PM, Maryana <nexnaru at gmail.com> wrote:

> 
> 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
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Kitware offers ITK Training Courses, for more information visit:
> http://kitware.com/products/protraining.php
> 
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-developers



More information about the Insight-developers mailing list