[ITK] [ITK-users] Loading a specifing region of an image from disk

Bradley Lowekamp blowekamp at mail.nih.gov
Mon Nov 3 15:38:18 EST 2014


Hello,

You might find this article useful I wrote on streaming ImageIO [1].


> 1.- How to set the RequestedRegion on a writer.

I am not sure what you are wanting to do. Are you wanting to extract a region from the input file and write a partial sub image?

There are two modes for the writer to drive this. 1) streaming - the sequential writing of sub-region of the whole image 2) pasting - updating a sub-region of an existing image file.


> 2.- Will the pipeline only load the requested region, including the reader?

The pipeline has a series of steps which include propagating a requested region, and giving each filter the opportunity to enlarge this region. I have frequently assemble pipelines which perform out-of-core processing as you desire. However all filters in the pipeline must support streaming, and not enlarging the requested region to the largest possible region.

Additionally the ImageIO for the reader and writer must also support streaming. There are several ImageIO's which support streaming reading (MRC,MetaIO, VTK, Nift, JPEG2000, etc), I believe that only MRC, VTK and MetaIO  fully support it for writing. So TIFF is currently not there.

Recently I have been working on improving the itkTIFFImageIO [2], and have performance gains of upto 3-5X from the prior version. However, I haven't gotten to adding streaming yet. It's is a back burner project for me to add support for stream reading to it, so that may be coming shortly ( this poking helps ). However, adding stream and paste writing is not planned.

Let's look at your code.

> I've tried myself but I can't get to write just the requested region.
> 
> The code:
> 
> int main( int argc, char* argv[] )
> {
> 
>   typedef unsigned char              PixelType;
>   typedef itk::Image< PixelType, 3 > ImageType;
> 
>   typedef itk::ImageFileReader< ImageType > ReaderFilterType;
>   ReaderFilterType::Pointer reader = ReaderFilterType::New();
>   reader->SetFileName("../data/
> Madrid_Train.tif");
>   ImageType::RegionType largest = reader->GetOutput()->GetLargestPossibleRegion();
>   ImageType::SizeType size   = largest.GetSize();
>   ImageType::IndexType index = largest.GetIndex();
> 
>   ImageType::RegionType half;
>   half.SetIndex(0,index[0] + 0.25*size[0]);
>   half.SetIndex(1,index[1] + 0.25*size[1]);
>   half.SetIndex(2,index[2] + 0.25*size[2]);
> 
>   half.SetSize(0,0.5*size[0]);
>   half.SetSize(1,0.5*size[1]);
>   half.SetSize(2,0.5*size[2]);
> 
>   typedef itk::ImageFileWriter< ImageType > WriterFilterType;
>   WriterFilterType::Pointer writer = WriterFilterType::New();
>   writer->SetFileName("image.tif");
>   reader->GetOutput()->SetRequestedRegion(half);
>   writer->SetInput(reader->GetOutput());
> 
>   try
>     {
>     //streamingFilter->Update();
>     writer->Update();
>     }
>   catch( itk::ExceptionObject & error )
>     {
>     std::cerr << "Error: " << error << std::endl;
>     return EXIT_FAILURE;
>     }

Unfortunately this is not the way the pipeline works. The reader does not actually read and update the image until the pipeline is updated. I would recommend additional reading about how a pipeline architecture works, perhaps from the ITK software guide or an VTK book.

For this case you should add in an ExtractImageFilter, or a CropImageFilter.

Brad




[1] http://www.kitware.com/media/html/IOStreamingInITK.html
[2] https://github.com/InsightSoftwareConsortium/ITK/commits/master/Modules/IO/TIFF
[3] http://www.itk.org/Doxygen/html/IO_2VisibleHumanStreamReadWrite_8cxx-example.html


On Nov 3, 2014, at 2:06 PM, Pol Monsó Purtí <lluna.nova at gmail.com> wrote:

> Hello everyone.
> 
> Two simple questions:
> 
> 
> By reading the itksoftware manual, section 8.3 Streaming Large Data it looks like by default reader filters only load the requested region.
> 
> We want to extract a specific region of a large 3D tiff image that does not fit in memory. This has to be as fast as possible.
> 
> I've taken a look at streaming, althought it's not exactly what we want since we don't want to process the full image.
> 
>   return EXIT_SUCCESS;
> }
> _____________________________________
> 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


More information about the Community mailing list