[Insight-users] Reusing WarpImageFilter for different regions?

Luis Ibanez luis.ibanez at kitware.com
Wed Jan 27 14:29:04 EST 2010


Hi George,

You may want to use:

         Filter->UpdateLargestPossibleRegion();

instead of

         Filter->Update();


The method UpdateLargestPossibleRegion()
repeats the pipeline region negotiations, while
the Update() method does not.


Let us know if you still find any problems,


     Thanks


            Luis

-------------------------------------------
On Wed, Jan 27, 2010 at 12:31 PM, g c <gc12358 at googlemail.com> wrote:
> Hi,
> 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:
> itk::InvalidRequestedRegionError (0xc6a3a0)
> Location: "virtual void itk::DataObject::PropagateRequestedRegion()"
> File: /Users/George/itk/InsightToolkit-3.14.0/Code/Common/itkDataObject.cxx
> Line: 397
> Description: Requested region is (at least partially) outside the largest
> possible region.
> Any ideas on what may cause this?
> Many thanks,
> George
>
> //========================================================
> // main.cxx
> //========================================================
> #include <itkExtractImageFilter.h>
> #include <itkImage.h>
> #include <itkLinearInterpolateImageFunction.h>
> #include <itkWarpImageFilter.h>
> typedef float DataType;
> typedef itk::Image< DataType, 3 > ImageType;
> typedef float CoordinateType;
> typedef itk::Vector< CoordinateType, 3 > VectorType;
> typedef itk::Image< VectorType, 3 > WarpFieldType;
> typedef itk::WarpImageFilter< ImageType, ImageType, WarpFieldType >
> WarpImageFilterType;
> typedef itk::ExtractImageFilter< WarpFieldType, WarpFieldType >
> WarpFieldExtractFilterType;
> // Reusing this global instance gives an error
> WarpImageFilterType::Pointer WarpImageFilter;
> void InterpolateImageSlice(
>     const unsigned int SliceNumber,
>     const unsigned int SliceDirection,
>     const ImageType * Image,
>     const WarpFieldType * WarpField )
> {
>     // Extract slice from warp field
>     WarpFieldExtractFilterType::Pointer Filter =
> WarpFieldExtractFilterType::New();
>     Filter->SetInput( WarpField );
>     WarpFieldType::RegionType Region =
> WarpField->GetLargestPossibleRegion();
>     Region.SetSize(  SliceDirection, 1 );
>     Region.SetIndex( SliceDirection, SliceNumber);
>     std::cout << Region << std::endl;
>     Filter->SetExtractionRegion( Region );
>     try
>     {
>         Filter->Update();
>     }
>     catch ( itk::ExceptionObject & err)
>     {
>         std::cout << err << std::endl;
>         return;
>     }
>     // Using a local instance of WarpImageFilter works, commented out for
> now
>     //WarpImageFilterType::Pointer WarpImageFilter =
> WarpImageFilterType::New();
>     WarpImageFilter->SetInput( Image );
>     WarpImageFilter->SetOutputParametersFromImage( Filter->GetOutput() );
>     WarpImageFilter->SetDeformationField( Filter->GetOutput() );
>     try
>     {
>         WarpImageFilter->Update();
>     }
>     catch ( itk::ExceptionObject & err)
>     {
>         std::cout << err << std::endl;
>         return;
>     }
> }
> int main( int argc, char* argv[] )
> {
>     // Set up image
>     ImageType::Pointer Image = ImageType::New();
>     ImageType::SizeType Size;
>     Size.Fill( 50 );
>     ImageType::IndexType Index;
>     Index.Fill( 0 );
>     ImageType::RegionType Region;
>     Region.SetSize( Size );
>     Region.SetIndex( Index );
>     Image->SetRegions( Region );
>     Image->Allocate();
>     // Set up warp field
>     WarpFieldType::Pointer WarpField = WarpFieldType::New();
>     WarpField->SetRegions( Region );
>     WarpField->Allocate();
>     WarpImageFilter = WarpImageFilterType::New();
>     InterpolateImageSlice( 25, 0, Image, WarpField );
>     InterpolateImageSlice( 25, 1, Image, WarpField );
>     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.html
>
> 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://www.itk.org/mailman/listinfo/insight-users
>
>


More information about the Insight-users mailing list