<div dir="ltr"><div><div><div><div><div><div>Hello everyone.<br><br></div><div>Two simple questions:<br><br></div><div>1.- How to set the RequestedRegion on a writer.<br></div><div>2.- Will the pipeline only load the requested region, including the reader?<br></div><div><br></div>By
reading the itksoftware manual, section 8.3 Streaming Large Data it
looks like by default reader filters only load the requested region.<br></div><br></div>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.<br><br></div>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.<br><br></div>I've tried myself but I can't get to write just the requested region.<br><br></div>The code:<br><br>int main( int argc, char* argv[] )<br>{<br><br> typedef unsigned char PixelType;<br> typedef itk::Image< PixelType, 3 > ImageType;<br><br> typedef itk::ImageFileReader< ImageType > ReaderFilterType;<br> ReaderFilterType::Pointer reader = ReaderFilterType::New();<br> reader->SetFileName("../data/<div>Madrid_Train.tif");<br> ImageType::RegionType largest = reader->GetOutput()->GetLargestPossibleRegion();<br> ImageType::SizeType size = largest.GetSize();<br> ImageType::IndexType index = largest.GetIndex();<br><br> ImageType::RegionType half;<br> half.SetIndex(0,index[0] + 0.25*size[0]);<br> half.SetIndex(1,index[1] + 0.25*size[1]);<br> half.SetIndex(2,index[2] + 0.25*size[2]);<br><br> half.SetSize(0,0.5*size[0]);<br> half.SetSize(1,0.5*size[1]);<br> half.SetSize(2,0.5*size[2]);<br><br> typedef itk::ImageFileWriter< ImageType > WriterFilterType;<br> WriterFilterType::Pointer writer = WriterFilterType::New();<br> writer->SetFileName("image.tif");<br> reader->GetOutput()->SetRequestedRegion(half);<br> writer->SetInput(reader->GetOutput());<br><br> try<br> {<br> //streamingFilter->Update();<br> writer->Update();<br> }<br> catch( itk::ExceptionObject & error )<br> {<br> std::cerr << "Error: " << error << std::endl;<br> return EXIT_FAILURE;<br> }<br><br> return EXIT_SUCCESS;<br>}</div></div>