[Insight-users] Help with the itk::ImportImageFilter object please.

Ricardo Ferrari ferrari.toronto at gmail.com
Wed May 16 09:55:00 EDT 2007


Hi Folks,

I am having problem to write to disk an image create dynamically. I am
sending a simple code I've created to understand the problem.
I really appreciate any help.

Thanks,
Ricardo


#include "itkImage.h"
#include "itkImageRegionIterator.h"
#include "itkImportImageFilter.h"
#include "itkImageFileWriter.h"


int main( int argc, char **argv )
{
   /// Define the pixel type
   typedef double
               PixelType;

   /// Define the image type and its iterator
   typedef itk::Image< PixelType, 3 >
ImageType3D;

   /// Define writer types
   typedef itk::ImageFileWriter< ImageType3D >
WriterType3D;

   /// Import filter used to write the gabor filter to disk
   typedef itk::ImportImageFilter< PixelType, 3 >
ImportFilter3D;


   // ***
   // Alloc memory dynamically
   // ***
   int m_dimU  = 256;
   int m_dimV  = 256;
   int m_dimW  = 128;

   const unsigned int nPixels =  m_dimU * m_dimV * m_dimW;
   PixelType *buffer = new PixelType[ nPixels ];
   // ***


   // ***
   // Create the import filter object
   // ***
   ImportFilter3D::Pointer importFilter = ImportFilter3D::New();

   ImportFilter3D::RegionType region;
   ImportFilter3D::IndexType start = {0, 0, 0};
   region.SetIndex( start );
   ImportFilter3D::SizeType size = {m_dimU, m_dimV, m_dimW};
   region.SetSize(  size  );

   importFilter->SetRegion( region );

   double origin[] = {0, 0, 0};
   importFilter->SetOrigin( origin );

   double spacing[] = {1.0, 1.0, 1.0};
   importFilter->SetSpacing( spacing );

   importFilter->SetImportPointer( buffer, nPixels, true );
   // ***


   // ***
   // Create the writer object
   // ***
   WriterType3D::Pointer writerPtr = WriterType3D::New();
   writerPtr->SetFileName( "C:\\Filter.gab" );
   writerPtr->SetInput( importFilter->GetOutput() );
   writerPtr->Update();      // ***

   return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070516/325f109b/attachment.html


More information about the Insight-users mailing list