<div class="gmail_quote">Hi,<div><br></div><div>I'm trying to use WarpImageFilter to interpolate single slices from an image by using differently sized regions (example code below). This works when I create a new instance of the WarpImageFilter for each slice, but gives the following error when I reuse the *same* WarpImageFilter for the second slice:</div>
<div><br></div><div><div>itk::InvalidRequestedRegionError (0xc6a3a0)</div><div>Location: "virtual void itk::DataObject::PropagateRequestedRegion()" </div><div>File: /Users/George/itk/InsightToolkit-3.14.0/Code/Common/itkDataObject.cxx</div>
<div>Line: 397</div><div>Description: Requested region is (at least partially) outside the largest possible region.</div><div><br></div><div>Any ideas on what may cause this?</div><div><br></div><div>Many thanks,</div><div>
<br>
</div><div>George</div><div><br></div><div><br></div><div>//========================================================</div><div><div>// main.cxx</div><div>//========================================================</div><div>
<br></div></div><div><div>#include <itkExtractImageFilter.h></div><div>#include <itkImage.h></div><div>#include <itkLinearInterpolateImageFunction.h></div><div>#include <itkWarpImageFilter.h></div>
<div><br></div><div>typedef float DataType;</div><div>typedef itk::Image< DataType, 3 > ImageType;</div><div>typedef float CoordinateType;</div><div>typedef itk::Vector< CoordinateType, 3 > VectorType;</div><div>
typedef itk::Image< VectorType, 3 > WarpFieldType;</div><div>typedef itk::WarpImageFilter< ImageType, ImageType, WarpFieldType > WarpImageFilterType;</div><div>typedef itk::ExtractImageFilter< WarpFieldType, WarpFieldType > WarpFieldExtractFilterType;</div>
<div><br></div><div>// Reusing this global instance gives an error</div><div>WarpImageFilterType::Pointer WarpImageFilter;</div><div><br></div><div>void InterpolateImageSlice(</div><div> const unsigned int SliceNumber,</div>
<div> const unsigned int SliceDirection,</div><div> const ImageType * Image,</div><div> const WarpFieldType * WarpField )</div><div>{</div><div> // Extract slice from warp field</div><div> WarpFieldExtractFilterType::Pointer Filter = WarpFieldExtractFilterType::New();</div>
<div> Filter->SetInput( WarpField );</div><div> WarpFieldType::RegionType Region = WarpField->GetLargestPossibleRegion();</div><div> Region.SetSize( SliceDirection, 1 );</div><div> Region.SetIndex( SliceDirection, SliceNumber);</div>
<div> std::cout << Region << std::endl;</div><div><br></div><div> Filter->SetExtractionRegion( Region );</div><div> try</div><div> {</div><div> Filter->Update();</div><div> }</div>
<div>
catch ( itk::ExceptionObject & err)</div><div> {</div><div> std::cout << err << std::endl;</div><div> return;</div><div> }</div><div><br></div><div> // Using a local instance of WarpImageFilter works, commented out for now</div>
<div> //WarpImageFilterType::Pointer WarpImageFilter = WarpImageFilterType::New();</div><div><br></div><div> WarpImageFilter->SetInput( Image );</div><div> WarpImageFilter->SetOutputParametersFromImage( Filter->GetOutput() );</div>
<div> WarpImageFilter->SetDeformationField( Filter->GetOutput() );</div><div> try</div><div> {</div><div> WarpImageFilter->Update();</div><div> }</div><div> catch ( itk::ExceptionObject & err)</div>
<div> {</div><div> std::cout << err << std::endl;</div><div> return;</div><div> }</div><div>}</div><div><br></div><div>int main( int argc, char* argv[] )</div><div>{</div><div> // Set up image</div>
<div> ImageType::Pointer Image = ImageType::New();</div><div> ImageType::SizeType Size;</div><div> Size.Fill( 50 );</div><div> ImageType::IndexType Index;</div><div> Index.Fill( 0 );</div><div> ImageType::RegionType Region;</div>
<div> Region.SetSize( Size );</div><div> Region.SetIndex( Index );</div><div> Image->SetRegions( Region );</div><div> Image->Allocate();</div><div><br></div><div> // Set up warp field</div><div> WarpFieldType::Pointer WarpField = WarpFieldType::New();</div>
<div> WarpField->SetRegions( Region );</div><div> WarpField->Allocate();</div><div><br></div><div> WarpImageFilter = WarpImageFilterType::New();</div><div> InterpolateImageSlice( 25, 0, Image, WarpField );</div>
<div><br></div><div> InterpolateImageSlice( 25, 1, Image, WarpField );</div><div><br></div><div> return EXIT_SUCCESS;</div><div>}</div><div><br></div></div></div>
</div><br>