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

Luis Ibanez luis.ibanez at kitware.com
Wed May 20 23:00:15 EDT 2009


Hi Nicolas,

Then problem may be that VTK is still giving you a 3D image
of one slice along a particular orientation (instead of a
real 2D slice).

What you may want to do, is to pass the full VTK image to an
ITK image (when using the export/import filters there is no
duplication of memory).

And then, once in ITK you use the ExtractImageFilter in order
to get a 2D image out of the 3D image.


     Regards,


         Luis


--------------------------
Nicolas Rannou wrote:
> 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
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at 
> http://www.kitware.com/opensource/opensource.html
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
> 
> 


More information about the Insight-users mailing list