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

Pol Monsó Purtí lluna.nova at gmail.com
Mon Nov 3 14:06:05 EST 2014


Hello everyone.

Two simple questions:

1.- How to set the RequestedRegion on a writer.
2.- Will the pipeline only load the requested region, including the reader?

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.

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;
    }

  return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20141103/5488b71b/attachment.html>


More information about the Insight-users mailing list