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

Pol Monsó Purtí lluna.nova at gmail.com
Mon Nov 3 17:58:40 EST 2014


Hello Bradley,

Thank you for your suggestions! I'm glad somebody is working on tif
streaming :) I answer below:


2014-11-03 21:38 GMT+01:00 Bradley Lowekamp <blowekamp at mail.nih.gov>:

> Hello,
>
> You might find this article useful I wrote on streaming ImageIO [1].
>
>
I've read the article early this afternoon and I found it very good and
encouraging. Specially *"The other difference is that the reader fully
supports streaming and only reads the required region from the file."*

That is exactly what we need. I was just wondering wether it splitted the
volume and took the chunks that intersected with the requested one or if it
really just loaded the requested one. I replicated that code taking out the
processing and just having a reader and a writer, but I didn't know how to
test that indeed it was just loading that requested piece.

So after reading your comments here I think streaming is the way to go. Can
you assert that only the requested region will be read?

>
> > 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.
>
>
I didn't expect that some would support reading but not writing. Actually
it's not mandatory for what we intend to do:

implifying, we have a huge image that we can't (and won't) load to disk.
Fortunatelly we are only interested in some specific chunks of it. So we
need to find a way to read those chunks, compute a simple operation and
then we can discard them. I wanted to write to check that indeed we were
retrieving the ROI and not the full image. We can't afford the reader to
read the whole image. We don't want to process the full image.

>
> > 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.
>
>
Yes, I've seen that not many support streaming. But in our case we would
just need a reader that can read a specific 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.
>

Yeah, we were thinking on using HDF5, but maybe you have some idea on what
would be best. That's another topic thought.

>
> 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.
>
>
Good work! 3-5x! That might be of interest actually for something else we
have. Can we pull your code?


> 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.
>
>
But if I use Extract or Crop, the reader is still loading the full image to
disk, isn't it?


> Brad
>
> Thank you for the article, I'll reproduce and let you know how it went.
>



> [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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20141103/9d7df4f0/attachment.html>


More information about the Insight-users mailing list