[ITK-users] Reading a very large image

Bradley Lowekamp blowekamp at mail.nih.gov
Tue Mar 3 09:27:11 EST 2015


Hello Vikram,

Unfortunately TIFFImageIO doesn't support streaming. So your code will try to load the whole things.

Perhaps you can find a machine with a large amount of memory and convert the TIFF to a mha file to perform ITK streaming processing on?

However, even if TIFFImageIO supported streaming your code would still try to read the largest possible region.

The ImageIORegion::SetIORegion is not a method that really should be used for IO streaming. For reading images the ITK pipeline architecture will take care of it automatically, by only reading the requested region. For writing the SetNumberOfStreamingDivisions methods can be set to sequentially write a region, and the ImageFileWriter::SetIORegion, can be use to only update a sub-region in the output.

I would strongly urge to read Section 8.3 of the new ITK Software guide[1][2], a couple of times. You need to be comfortable processing images with the LargestPossibleRegion being different than the buffered region. As well as know that just calling Update, is the same thing as calling UpdateLargestPossibleRegion

Consider the following changes:

1) Remove the manual setup of the ImageIO, just let the factory take care of it.
2) Replace the Update call with: SetRequestedRegion(region) followed by PropagateRequestedRegion(). ( This will not cause memory allocation or reading. It'll just determine what the ImageIO can read).
3) Print the output, of the image reader. Noting the LargestPossibleRegion, BufferedRegion and the RequestedRegion.

Hope that gets you started,
Brad


[1] http://www.itk.org/ITK/resources/software.html
[2] http://www.amazon.com/ITK-Software-Guide-Book-Introduction/dp/1930934270/ref=sr_1_1?ie=UTF8&qid=1425392002&sr=8-1&keywords=ITK+Software


Pol,

Yes, I did a bit of work on the TIFFImageIO for the 4.7 ITK release, to improve performance (~3-5X) and add support for the TIFF tags in the meta-data dictionary. This took a good bit of time, and just improving the read performance was sufficient for my project, and I didn't need streaming. It would certainly be nice to add streaming, but I haven't gotten around to it. Letting me know it's important to people certainly helps prioritize :)

Brad


On Mar 3, 2015, at 4:35 AM, Pol Monsó Purtí <lluna.nova at gmail.com> wrote:

> Hello Vikram,
> 
> 
> I followed the same road a few months ago, read the kind and insightful answer of Bradley here: http://public.kitware.com/pipermail/community/2014-November/007678.html
> 
> tl; dr
> @Bradley is working on streaming the tiff reader, but it isn't ready yet (right? I apologize for not having had the time to test it). So indeed, your reader is reading the whole image. Try using mha instead if possible.
> 
> 
> 2015-03-03 8:19 GMT+01:00 Vikram Venkatraghavan <88.vikram at gmail.com>:
> Hello,
> 
> I am relatively new to ITK. I am trying to read a very large TIFF image using the IO streaming functionality in ITK. I am reading a very small portion of the image and I still end up getting memory allocation error. I get the feeling, the code is trying to read the entire image at once, even after specifying the region to read. Can someone please tell what is wrong the following code snippet ?
> 
> typedef itk::RGBPixel< unsigned char >  RGBPixelType;
> typedef itk::Image< RGBPixelType, 2 >   RGB2DImageType;
> typedef itk::ImageFileReader<RGB2DImageType> RGBReaderType;
> 
> itk::TIFFImageIO::Pointer tiffIO = itk::TIFFImageIO::New();
> tiffIO->SetPixelType(itk::ImageIOBase::RGBA);
> 
> RGB2DImageType::SizeType sz;
> RGB2DImageType::IndexType idx;
> sz[0]=128; sz[1]=128;
> idx[0]=0; idx[1]=0;
> 
> itk::ImageIORegion region(2);
> region.SetSize(0,sz[0]);
> region.SetSize(1,sz[1]);
> region.SetIndex(0,idx[0]);
> region.SetIndex(1,idx[1]);
> tiffIO->SetIORegion(region);
> 
> RGBReaderType::Pointer reader = RGBReaderType::New();
> reader->SetFileName("V:\\TiFF_Image.tiff");
> reader->SetImageIO(tiffIO);
> reader->SetUseStreaming(1);
> reader->Update();
> 
> Thanks in advance.
> 
> Regards,
> Vikram
> 
> _____________________________________
> 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://www.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-users
> 
> 
> _____________________________________
> 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://www.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-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20150303/a061e176/attachment.html>


More information about the Insight-users mailing list