[Insight-users] VTK to ITK / Requested region is (at least partially) outside the largest possible region

Nicolas Rannou nrannou at bwh.harvard.edu
Thu May 14 18:15:23 EDT 2009


Hi all,

I'm currently trying to convert my VTK image to an ITK image then apply 
some itk filters. But an errore occurs after the ShrinkImageFilter.

I first extract a slide from my vtk input volume :
/------------------------------------------------------------------------------------------------------------------------------/
  this->ImageClip = vtkImageClip::New();
  this->ImageClip->SetInput(inVolume->GetImageData());
  this->ImageClip->ClipDataOn();
  this->ImageClip->SetOutputWholeExtent(bounds[1]/2, 
bounds[1]/2,bounds[2], bounds[3],bounds[4], bounds[5]);
  this->ImageClip->Update();
 
  this->CurrentSlide = vtkImageData::New();
  this->CurrentSlide->DeepCopy( this->ImageClip->GetOutput());
/------------------------------------------------------------------------------------------------------------------------------/


then I convert this slice into an ITK image and process it.


/--------------------------------------------------------------------------------------------------------------------------------/
  typedef itk::Image< float,  2 >   InputImageType;
  typedef itk::Image< unsigned char,   2 >   MaskImageType;
  typedef itk::Image< float,  2 >   OutputImageType;
  typedef itk::Image< float, 2 >  InternalImageType;

//Convert the input vtk image into float

  vtkImageCast* VtkCaster = vtkImageCast::New();
  VtkCaster->SetInput(this->CurrentSlide);
  VtkCaster->SetOutputScalarTypeToFloat();
 
//Convert the vtk image into ITK

    typedef itk::VTKImageToImageFilter< InternalImageType 
 >VTK2ITKConnectorFilterType;
    VTK2ITKConnectorFilterType::Pointer VTK2ITKconnector 
=VTK2ITKConnectorFilterType::New();
    VTK2ITKconnector->SetInput( VtkCaster->GetOutput() );
    VTK2ITKconnector->GetImporter()->Update();
    VTK2ITKconnector->Update();

//Use ITK Filters
                             
  typedef itk::ShrinkImageFilter<InputImageType, InputImageType> 
ShrinkerType;
  ShrinkerType::Pointer shrinker = ShrinkerType::New();
  shrinker->SetInput( VTK2ITKconnector->GetOutput() );
  shrinker->SetShrinkFactors( 1 );                                    
                                      
   
  typedef itk::BinaryThresholdImageFilter<InputImageType, 
MaskImageType>  mFilterType;
              
  mFilterType::Pointer mfilter = mFilterType::New(); 
  mfilter->SetInput( VTK2ITKconnector->GetOutput() );
  
mfilter->SetLowerThreshold(10);//this->ThresholdingFilterNode->GetConductance());
  mfilter->SetOutsideValue(0);
  mfilter->SetInsideValue(1); 
  mfilter->UpdateLargestPossibleRegion();
  
  MaskImageType::Pointer maskImage = NULL;
 
  maskImage = mfilter->GetOutput();
  typedef itk::ShrinkImageFilter<MaskImageType, MaskImageType> 
MaskShrinkerType;
  MaskShrinkerType::Pointer maskshrinker = MaskShrinkerType::New();
  maskshrinker->SetInput( maskImage );
  maskshrinker->SetShrinkFactors( 1 );
  shrinker->SetShrinkFactors( 3 );
  maskshrinker->SetShrinkFactors(3 );
 
  shrinker->Update();
  shrinker->UpdateLargestPossibleRegion();
  maskshrinker->Update();
  maskshrinker->UpdateLargestPossibleRegion();
/--------------------------------------------------------------------------------------------------------------------------------/
when I call update on the shrink filters, an error occurs:

/----------------------------------------------------------------------------------------------------------------------------------------------/
ERROR: In 
/projects/nacvisitors/nrannou/Slicer3/Slicer3-lib/KWWidgets/vtkKWApplication.cxx, 
line 1286
vtkSlicerApplication (0xefa4d0): TclTk error: Uncaught exception: 
/projects/nacvisitors/nrannou/Slicer3/Slicer3-lib/Insight/Code/Common/itkDataObject.cxx:397:
Requested region is (at least partially) outside the largest possible 
region.
/----------------------------------------------------------------------------------------------------------------------------------------------/

so I added, as recommended in some posts on the web :

//---------------------------------------------------------------------------------/

  Insight/Code/Common/itkImageBase.cxx

and in line: 351, just at the end of the method
VerifyRequestedRegion(), add the following:

if( retval == false )
{
std::cout << this->GetRequestedRegion() << std::endl;
std::cout << this->GetLargestPossibleRegion() << std::endl;
}/

///-----------------------------------------------------------------///
here is what I get when I launch my module on a volume, extract a slice, 
convert a slice into itk then process it:
/
/-------------------------------------------------------/
ImageRegion (0x5f5fff0)
  Dimension: 2
  Index: [129, 0]
  Size: [3, 255]

ImageRegion (0x5f5ffc8)
  Dimension: 2
  Index: [127, 0]
  Size: [1, 256]/
/--------------------------------------------------------/

the problem is clear, there is a problem in my indexes but I couldn't 
find out how to solve it.
The strange thing is that the problem occurs only when I extract a slice 
from my vtk volume, then convert and process it
If I convert then process my whole vtk volume it works. The problem must 
then be linked to my extraction of the slice but I can't see where the 
problem is.

Thanks,
Nicolas


More information about the Insight-users mailing list