Hi Folks, <br><br>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. <br>I really appreciate any help. <br><br>Thanks, <br>Ricardo <br><br>
<br>#include "itkImage.h" <br>#include "itkImageRegionIterator.h" <br>#include "itkImportImageFilter.h" <br>#include "itkImageFileWriter.h" <br><br><br>int main( int argc, char **argv )
<br>{ <br> /// Define the pixel type <br> typedef double PixelType; <br><br> /// Define the image type and its iterator <br> typedef itk::Image< PixelType, 3 > ImageType3D;
<br><br> /// Define writer types <br> typedef itk::ImageFileWriter< ImageType3D > WriterType3D; <br><br> /// Import filter used to write the gabor filter to disk <br> typedef itk::ImportImageFilter< PixelType, 3 > ImportFilter3D;
<br><br><br> // *** <br> // Alloc memory dynamically <br> // *** <br> int m_dimU = 256; <br> int m_dimV = 256; <br> int m_dimW = 128; <br><br> const unsigned int nPixels = m_dimU * m_dimV * m_dimW; <br> PixelType *buffer = new PixelType[ nPixels ];
<br> // *** <br><br><br> // *** <br> // Create the import filter object <br> // *** <br> ImportFilter3D::Pointer importFilter = ImportFilter3D::New(); <br><br> ImportFilter3D::RegionType region; <br> ImportFilter3D::IndexType start = {0, 0, 0};
<br> region.SetIndex( start ); <br> ImportFilter3D::SizeType size = {m_dimU, m_dimV, m_dimW}; <br> region.SetSize( size ); <br><br> importFilter->SetRegion( region ); <br><br> double origin[] = {0, 0, 0}; <br>
importFilter->SetOrigin( origin ); <br><br> double spacing[] = {1.0, 1.0, 1.0}; <br> importFilter->SetSpacing( spacing ); <br><br> importFilter->SetImportPointer( buffer, nPixels, true ); <br> // *** <br>
<br><br> // *** <br> // Create the writer object <br> // *** <br> WriterType3D::Pointer writerPtr = WriterType3D::New(); <br> writerPtr->SetFileName( "C:\\Filter.gab" ); <br> writerPtr->SetInput( importFilter->GetOutput() );
<br> writerPtr->Update(); // *** <br><br> return 0; <br>} <br><br>