[Insight-users] about converting images and memory

barbababa tonimuusimaki at gmail.com
Wed Jun 29 13:34:02 EDT 2011


Hello  all,

i tried to find some info about this subject but did not find anything. I am
using ITK
libraries in an external application and currently i am writing different
functions, which all
have the following pipeline:

1. Convert the original image to ITK
2. Use 1. as input to some filter
3. Convert the output of that filter back to the application

So i have 4 times the amount of allocated memory of that the original image!
This means i can not
do much with 3D images. Currently i am using the below code for converting
3D float images.
My question is, is there any other way of doing this? Something like
allocating only the input and output image. 64bit OS and increasing cache
are some solutions but are there  others?

Thanks,
toni



#include <itkImage.h>
#include <string>
#define _GATAN_USE_STL_STRING		// Provide conversion from 'DM::String' to
'std::string'

#include "itkImportImageFilter.h"

#define _GATANPLUGIN_USES_LIBRARY_VERSION 2
#include "DMPlugInBasic.h"

typedef itk::Image< float, 3> ItkImage3;
typedef float PixelType;


ItkImage3::Pointer dmtoitk3( DM::Image input )
{
	
  typedef itk::ImportImageFilter< PixelType, 3>  ImportFilterType;
  
  ImportFilterType::Pointer importFilter = ImportFilterType::New();

  ImportFilterType::SizeType  size;

  size[0]  = input.GetDimensionSize( 0 );	 
  size[1]  = input.GetDimensionSize( 1 );
  size[2]  = input.GetDimensionSize( 2 );

  ImportFilterType::IndexType start;
  start.Fill( 0 );

  ImportFilterType::RegionType region;
  region.SetIndex( start );
  region.SetSize(  size  );

  importFilter->SetRegion( region );

  double origin[3 ];
  origin[0] = 0.0;    // X coordinate 
  origin[1] = 0.0;    // X coordinate 
  origin[2] = 0.0;    // X coordinate 

  importFilter->SetOrigin( origin );

  double spacing[ 3];
  spacing[0] = 1.0;    // along X direction 
  spacing[1] = 1.0;    // along X direction
  spacing[2] = 1.0;    // along X direction

  importFilter->SetSpacing( spacing );

  const unsigned int numberOfPixels = size[0]*size[1]*size[2] ;
  const unsigned int numberOfBytes = numberOfPixels * sizeof( PixelType );

    const bool importImageFilterWillOwnTheBuffer = false;

    PixelType * localBuffer = new PixelType[numberOfPixels];
    
	PlugIn::ImageDataLocker inputl( input,
PlugIn::ImageDataLocker::lock_data_CONTIGUOUS );

    memcpy(localBuffer, inputl.get_image_data().get_data(), numberOfBytes);

    importFilter->SetImportPointer( localBuffer, numberOfPixels, 
                                    importImageFilterWillOwnTheBuffer );
 

  importFilter->Update();

  ItkImage3::Pointer output = importFilter->GetOutput();

  output->DisconnectPipeline();

  return output;
}

--
View this message in context: http://itk-insight-users.2283740.n2.nabble.com/about-converting-images-and-memory-tp6529969p6529969.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.


More information about the Insight-users mailing list