[Insight-users] itk image memory allocation 32 bit

Joachimgiard joachim.giard at uclouvain.be
Wed Jan 18 11:03:11 EST 2012


Hello,

I try to create two 3D images to perform a registration. I have to convert
the image from another format, so I first create an image and allocate the
memory. It works on Linux 64bit configurations but crashes on Windows 32 bit
configurations. Size, spacing and origin are read from the other format, are
correct and "classical". If I could fragment the memory allocation, for
instance by storing the image as slices instead of one volume, the
allocation would be easier. Any idea? Thank you

Joachim

/******
* code *
******/

   typedef double PixelType;
   typedef itk::Image<PixelType,3> ITKImageType;

   ITKImageType::RegionType::SizeType size;
   ITKImageType::SpacingType spacing;
   double origin[3];

   //typically 512 512 139
   size[0] = inputVolume->getSize(0);
   size[1] = inputVolume->getSize(1);
   size[2] = inputVolume->getSize(2);

  //typically 0.49 0.49 1
   spacing[0] = inputVolume->getSpacing(0);
   spacing[1] = inputVolume->getSpacing(1);
   spacing[2] = inputVolume->getSpacing(2);

   //typically 0 0 0
   origin[0] = inputVolume->getOrigin(0);
   origin[1] = inputVolume->getOrigin(1);
   origin[2] = inputVolume->getOrigin(2);

   ITKImageType::RegionType outputRegion;
   ITKImageType::RegionType::IndexType outputStart;
   outputStart[0] = 0;
   outputStart[1] = 0;
   outputStart[2] = 0;
   outputRegion.SetSize(size);
   outputRegion.SetIndex(outputStart);

   ITKImageType::Pointer outputImage = ITKImageType::New();
   outputImage->SetRegions(outputRegion);
   outputImage->SetSpacing(spacing);
   outputImage->SetOrigin(origin);

   try {
       outputImage->Allocate();
   } catch (itk::MemoryAllocationError &ex) {
       qWarning() << "Unable allocate memory for ITK image";
       throw ex;
   }

/**************
* end of the code *
***************/

I also tried using StreamingImageFilter but I'm not sure whether it is could
help or not. Moreover, I'm not sure to use it well.

/******
* code *
******/
   typedef itk::StreamingImageFilter<ITKImageType,ITKImageType>
StreamingFilterType;

....

   ITKImageType::Pointer outputImage = ITKImageType::New();
   outputImage->SetRegions(outputRegion);
   outputImage->SetSpacing(spacing);
   outputImage->SetOrigin(origin);

   StreamingFilterType::Pointer streamingFilter =
StreamingFilterType::New();
   streamingFilter->SetNumberOfStreamDivisions(10);
   streamingFilter->SetInput( outputImage );
   streamingFilter->GraftOutput( outputImage );
   streamingFilter->Update();

   try {
       outputImage->Allocate();
   } catch (itk::MemoryAllocationError &ex) {
       qWarning() << "Unable allocate memory for ITK image";
       throw ex;
   }


/**************
* end of the code *
***************/

-- 
View this message in context: http://old.nabble.com/itk-image-memory-allocation-32-bit-tp33162185p33162185.html
Sent from the ITK - Users mailing list archive at Nabble.com.



More information about the Insight-users mailing list