<div dir="ltr"><div>Hi!</div><div><br></div>If anyone would like to repeat the test, this is my test file: <a href="https://www.dropbox.com/s/7hpen46znk1h58l/brain_8bit.nii?dl=0">https://www.dropbox.com/s/7hpen46znk1h58l/brain_8bit.nii?dl=0</a><div>If I convert that file to MetaIO without streams, and use ExtractImageFilter to read one file perpendicular to Y (as in the code I'm sending bellow) it works fine (see slice.tif). However if I convert it to MetaIO using streams and use the same code to read the same slice, I end up with a truncated image (file slice_stream.tif). I have the same result when I use Paraview for visualization. By the way, for what I've read from ITK documentation NIfti supposedly supports streamed reading. So I'm guessing that using Nifti in this case would be ok. Is this correct? Would anyone have an idea on what's wrong?</div><div><br></div><div>Thank you!</div><div><br></div><div><br></div><div><br></div><div>Code for reading slice: </div><div><br></div><div><br></div><div><br></div><div><div>#include "itkImageFileReader.h"</div><div>#include "itkImageFileWriter.h"</div><div>#include "itkExtractImageFilter.h"</div><div>#include "itkImage.h"</div><div><br></div><div><br></div><div>int main( int argc, char ** argv )</div><div>{</div><div><br></div><div> typedef unsigned char InputPixelType;</div><div> typedef unsigned char OutputPixelType;</div><div><br></div><div> typedef itk::Image< InputPixelType, 3 > InputImageType;</div><div> typedef itk::Image< OutputPixelType, 2 > OutputImageType;</div><div><br></div><div> typedef itk::ImageFileReader< InputImageType > ReaderType;</div><div> typedef itk::ImageFileWriter< OutputImageType > WriterType;</div><div> </div><div> std::string fileIn = "mri2_stream.mha";</div><div> std::string fileOut = "slice.tif";</div><div> const char * inputFilename = fileIn.c_str();</div><div> const char * outputFilename = fileOut.c_str();</div><div><br></div><div> ReaderType::Pointer reader = ReaderType::New();</div><div> WriterType::Pointer writer = WriterType::New();</div><div><br></div><div> reader->SetFileName( inputFilename );</div><div> writer->SetFileName( outputFilename );</div><div><br></div><div> typedef itk::ExtractImageFilter< InputImageType, OutputImageType > FilterType;</div><div> FilterType::Pointer filter = FilterType::New();</div><div> filter->InPlaceOn();</div><div> filter->SetDirectionCollapseToSubmatrix();</div><div><br></div><div> reader->UpdateOutputInformation();</div><div> InputImageType::RegionType inputRegion = reader->GetOutput()->GetLargestPossibleRegion();</div><div><br></div><div> InputImageType::SizeType size = inputRegion.GetSize();</div><div> </div><div> std::cout << "Size: " << std::endl;</div><div> std::cout << size[0] << std::endl;</div><div> std::cout << size[1] << std::endl;</div><div> std::cout << size[2] << std::endl;</div><div> </div><div> </div><div> InputImageType::IndexType start = inputRegion.GetIndex();</div><div> const unsigned int sliceNumber = 800;</div><div> </div><div> std::cout << "Start: " << std::endl;</div><div> std::cout << start[0] << std::endl;</div><div> std::cout << start[1] << std::endl;</div><div> std::cout << start[2] << std::endl;</div><div> </div><div> size[1] = 0;</div><div> start[1] = sliceNumber;</div><div><br></div><div> InputImageType::RegionType desiredRegion;</div><div> desiredRegion.SetSize( size );</div><div> desiredRegion.SetIndex( start );</div><div><br></div><div> filter->SetExtractionRegion( desiredRegion );</div><div><br></div><div> filter->SetInput( reader->GetOutput() );</div><div> writer->SetInput( filter->GetOutput() );</div><div><br></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><br></div><div><br></div><div> return EXIT_SUCCESS;</div><div>}</div></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 21, 2015 at 12:07 PM, Maryana <span dir="ltr"><<a href="mailto:nexnaru@gmail.com" target="_blank">nexnaru@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><div dir="ltr"><div style="font-size:12.8000001907349px">Hi,</div><div style="font-size:12.8000001907349px"><br></div><span style="font-size:12.8000001907349px">I use Linux Mint 64bits, GCC 4.8, Cmake 2.8. I'm compiling to this platform. </span><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">Thank you!</div></div></span><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Mon, Sep 21, 2015 at 11:55 AM, Bradley Lowekamp <span dir="ltr"><<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>></span> wrote:<br></span><div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Maryana,<br>
<br>
What compiler, platform and architecture are you compiling for?<br>
<br>
Brad<br>
<div><div><br>
On Sep 21, 2015, at 2:54 PM, Maryana <<a href="mailto:nexnaru@gmail.com" target="_blank">nexnaru@gmail.com</a>> wrote:<br>
<br>
><br>
> Hi ITK Users/Devs,<br>
><br>
> 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?<br>
><br>
> Thank you!<br>
><br>
> #include <cstdlib><br>
> #include <string><br>
> #include <iostream><br>
><br>
> #include "itkImage.h"<br>
> #include "itkImageFileReader.h"<br>
> #include "itkImageFileWriter.h"<br>
> #include "itkImageRegionIterator.h"<br>
> #include "itkNiftiImageIO.h"<br>
> #include "itkMetaImageIO.h"<br>
><br>
><br>
> int main(int argc, char const *argv[]){<br>
><br>
> std::string fileIn = "brain_8bit.nii";<br>
> std::string fileOut = "mri2_stream.mha";<br>
><br>
> typedef itk::Image<unsigned char,3> Image3D;<br>
><br>
> //Reader<br>
> typedef itk::ImageFileReader<Image3D> ReaderType;<br>
> ReaderType::Pointer reader = ReaderType::New();<br>
> reader->SetFileName(fileIn);<br>
><br>
> //Writer<br>
> typedef itk::ImageFileWriter<Image3D> WriterType;<br>
> WriterType::Pointer writer = WriterType::New();<br>
> writer->SetFileName(fileOut);<br>
> writer->SetNumberOfStreamDivisions(20);<br>
> writer->SetInput(reader->GetOutput());<br>
><br>
><br>
> std::cout << "Input: " << fileIn << std::endl;<br>
> std::cout << "Output: " << fileOut << std::endl;<br>
><br>
> std::cout << "Writing..." << std::endl;<br>
> try<br>
> {<br>
> writer->Update();<br>
> }<br>
> catch( itk::ExceptionObject & err )<br>
> {<br>
> std::cerr << "ExceptionObject caught !" << std::endl;<br>
> std::cerr << err << std::endl;<br>
> return EXIT_FAILURE;<br>
> }<br>
> std::cout << "Finished." << std::endl;<br>
><br>
><br>
> return EXIT_SUCCESS;<br>
> }<br>
><br>
><br>
><br>
><br>
><br>
> --<br>
> "Tudo no mundo começou com um sim. Uma molécula disse sim a outra molécula e nasceu a vida" - Clarice Lispector<br>
</div></div>> _______________________________________________<br>
> Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Kitware offers ITK Training Courses, for more information visit:<br>
> <a href="http://kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://kitware.com/products/protraining.php</a><br>
><br>
> Please keep messages on-topic and check the ITK FAQ at:<br>
> <a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://public.kitware.com/mailman/listinfo/insight-developers" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/insight-developers</a><br>
<br>
</blockquote></div></div></div><div><div class="h5"><br><br clear="all"><div><br></div>-- <br><div>"Tudo no mundo começou com um sim. Uma molécula disse sim a outra molécula e nasceu a vida" - Clarice Lispector</div>
</div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">"Tudo no mundo começou com um sim. Uma molécula disse sim a outra molécula e nasceu a vida" - Clarice Lispector</div>
</div>