[Insight-users] Dose resample filter support vector field?

Hsiang-Chi Kuo kuoxgx at gmail.com
Mon Feb 16 21:32:22 EST 2009


  I have tried itkVectorResampleImageFilter. Now my code can be complied,
   however, I still get the following error message when I run the program:

   itk::ExceptionObject (010DF768)
   Location: "class itk::Vector<float,3> *__thiscall
   itk::ImportImageContainer<unsi
   gned long,class itk::Vector<float,3> >::AllocateElements(unsigned long)
   const"
   File:
c:\itk\insighttoolkit-3.10.1\code\common\itkImportImageContainer.txx
   Line: 194
   Description: Failed to allocate memory for image.

   The image file I am running is 512x512x46 (~25M). I slightly extracted
the
   file into 22M and obtained a deform field (DF.mhd) of 62M. I tried the
   itkVectorResampleImageFilter to restored the deform field (DF_EX.mhd) to
   orginal size (physical size) but with less resolution. Theoretically
   DF_EX.mhd is less size (in memory) than DF.mhd. How come I still get the
   "Failed to allocate memory for image"?
   Attached is my code to resample the vector field.
   Regards,
   Howard

On Sun, Feb 15, 2009 at 7:57 AM, Bill Lorensen <bill.lorensen at gmail.com>wrote:

> Try itkVectorResampleImageFilter.
>
> Examples/Filtering/ResampleImageFilter9.cxx illustrates the class.
>
> On Sat, Feb 14, 2009 at 4:11 PM, Hsiang-Chi Kuo <kuoxgx at gmail.com> wrote:
> > Hi,
> >
> >  I am working on a deformable registration program with the diffeomorphic
> >   Demons registration filter. Due to the memory issue, I have to apply
> the
> >   region of interest filer to the input image such that I can run the
> > program  and get the deform field. Then I tried to use resample image
> filter
> > to
> >   restore the size of the deform field back to the original size of the
> > input image. First, the resample image  filter dose not allow me to set
> the
> >   default pixel to zero. If I by pass the setting of the background to
> > zero, it turn out the attached error message.
> >   Dose the resample image filter support vector field? If not, any way I
> > can solve my problem? Bellowed please also find part of my code.
> >   Thanks and regards,
> > Howard
> >
> > typedef itk::Image< VectorPixelType, Dimension >   DeformationFieldType;
> >   typedef itk::ImageFileWriter< DeformationFieldType >  FieldWriterType;
> >
> >   typename FieldWriterType::Pointer fieldWriter = FieldWriterType::New();
> >   fieldWriter->SetFileName( args.outputFieldFile0.c_str() );
> >
> >   typedef
> > itk::ResampleImageFilter<DeformationFieldType,DeformationFieldType>
> > FilterType;
> >   FilterType::Pointer resampleFilter = FilterType::New();
> >
> >   typedef itk::AffineTransform< double, Dimension >  TransformType;
> >
> >   TransformType::Pointer transform = TransformType::New();
> >   resampleFilter->SetTransform( transform );
> >
> >   typedef itk::NearestNeighborInterpolateImageFunction<
> >                        DeformationFieldType, double >  InterpolatorType;
> >
> >   InterpolatorType::Pointer interpolator = InterpolatorType::New();
> >   resampleFilter->SetInterpolator( interpolator );
> >
> >   //resampleFilter->SetDefaultPixelValue( 0 );
> >
> >   typename ImageType::Pointer outputImage = 0;
> >   outputImage = outputImageReader -> GetOutput();
> >   resampleFilter->SetSize(
> > outputImage->GetLargestPossibleRegion().GetSize() );
> >   resampleFilter->SetInput( defField );
> >   fieldWriter->SetInput( resampleFilter->GetOutput() );
> >   fieldWriter->SetUseCompression( true );
> >
> >   try
> >       {
> >          fieldWriter->Update();
> >       }
> >       catch( itk::ExceptionObject& err )
> >       {
> >          std::cout << "Unexpected error." << std::endl;
> >          std::cout << err << std::endl;
> >          exit( EXIT_FAILURE );
> >       }
> > _____________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.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
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090216/076217ff/attachment-0001.htm>
-------------- next part --------------
const unsigned int VectorDimension = 3;
	  typedef itk::Vector< float, VectorDimension >    PixelType;
	  typedef itk::Image< PixelType, Dimension > ImageType;
	  
	  typedef itk::ImageFileReader< ImageType > ReaderType;
      typedef itk::ImageFileWriter< ImageType > WriterType;
	  
	  typename ReaderType::Pointer fieldReader = ReaderType::New();
      fieldReader->SetFileName( args.outputFieldFile.c_str() );
	  
	  fieldReader->Update();
   
  typename WriterType::Pointer fieldWriter = WriterType::New();

  fieldWriter->SetFileName( args.outputFieldFile_EX.c_str() );
  
  typedef itk::VectorResampleImageFilter<ImageType,ImageType> FilterType;
  FilterType::Pointer nearestResampleFilter = FilterType::New();  
 
  typedef itk::IdentityTransform< double, Dimension >  TransformType;
  
  TransformType::Pointer transform = TransformType::New();
  nearestResampleFilter->SetTransform( transform );
  
  typedef itk::VectorNearestNeighborInterpolateImageFunction< 
                       ImageType, double >  InterpolatorType;
  
  InterpolatorType::Pointer vectorInterpolator = InterpolatorType::New();
  nearestResampleFilter->SetInterpolator( vectorInterpolator );
  
   PixelType defaultValue;
   defaultValue.Fill(0);
 
  nearestResampleFilter->SetDefaultPixelValue( defaultValue );
  
  ImageType::SpacingType spacing;
  spacing[0] = .5; // pixel spacing in millimeters along X
  spacing[1] = .5; // pixel spacing in millimeters along Y
  spacing[2] = .5; // pixel spacing in millimeters along Z
     
  typedef itk::Image< PixelType, Dimension >  MovingImageType;
  //typename MovingImageType::Pointer movingImage = 0;
  typedef itk::ImageFileReader< ImageType > MovingImageReaderType;
   typename MovingImageReaderType::Pointer movingImageReader
      = MovingImageReaderType::New();  
   movingImageReader->SetFileName( args.movingImageFile0.c_str() );    
   movingImageReader->Update();

  typedef MovingImageType::SpacingType    SpacingType;
  typedef MovingImageType::PointType      OriginType;
  typedef MovingImageType::RegionType     RegionType;
  typedef MovingImageType::SizeType       SizeType;
   
   MovingImageType::Pointer movingImage = movingImageReader -> GetOutput();
   
  const SpacingType movingSpacing= movingImage->GetSpacing();
   const OriginType movingOrigin=movingImage->GetOrigin();
  const RegionType movingRegion=movingImage->GetLargestPossibleRegion();
  const SizeType movingSize=movingRegion.GetSize();
  
  ImageType::SizeType newSize;
  newSize[0] = movingSize[0]/(spacing[0]/movingSpacing[0]);
  newSize[1] = movingSize[1]/(spacing[1]/movingSpacing[1]);
  newSize[2] = movingSize[2]/(spacing[2]/movingSpacing[2]);
   
   std::cout << "Size = " << movingImage->GetLargestPossibleRegion().GetSize() <<std::endl;
	
   nearestResampleFilter->SetOutputOrigin(  movingImage->GetOrigin() );  
   nearestResampleFilter->SetOutputSpacing( spacing );
   nearestResampleFilter->SetSize(  newSize );
   nearestResampleFilter->SetInput( fieldReader->GetOutput() );
  fieldWriter->SetInput(  nearestResampleFilter->GetOutput() );
  fieldWriter->SetUseCompression( true );
    
  try
      {
         fieldWriter->Update();
      }
      catch( itk::ExceptionObject& err )
      {
         std::cout << "Unexpected error." << std::endl;
         std::cout << err << std::endl;
         exit( EXIT_FAILURE );
      }
 }


More information about the Insight-users mailing list