[Insight-users] Reusing WarpImageFilter for different regions?

g c gc12358 at googlemail.com
Wed Jan 27 12:31:36 EST 2010


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;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100127/232405f7/attachment.htm>


More information about the Insight-users mailing list