[Insight-users] In / out

Luis Ibanez luis.ibanez at kitware.com
Sun Aug 28 12:42:42 EDT 2005



Hi Daniel,

Your code looks good,

In order to identify whether the problem is in
the transfer of data from your app to ITK, or
from ITK to your app, please add two writers,
one that writes your image as it is received at
the Import filter, and another one that writes
it as it is produced at the output of the
Thresholding filter.


The code will be like:

   typedef itk::ImageFileWriter< ImageType > WriterType;

   WriterType::Pointer writer1 = WriterType::New();
   WriterType::Pointer writer2 = WriterType::New();

   writer1->SetFileName("file1.mhd");
   writer2->SetFileName("file2.mhd");

   writer1->SetInput( importer->GetOutput() );
   writer2->SetInput( file->GetOutput() );

Then, add a writer1 update after you update the importer,

   importer->Update();
   writer1->Update();

and a writer2 update after you update the thresholding
filter.

   file->Update();
   writer2->Update();



You can look at the resulting images with the ImageViewer
available in InsightApplications, or with ParaView that
can be downloaded for free from www.paraview.org.



By writing these two images, we will know if data
is getting lost along the way.



Please let us know what you find.


    Thanks


       Luis


--------------------
Einstein, Daniel R wrote:
> Hello,
> 
> Terribly sorry. I have read the UG and looked over the tutorials 
> concerning reading and writing to a buffer. My code compiles and runs …. 
> but does nothing. To troubleshoot, I have implemented as fast and naïve 
> threshold filter. Could someone please look this over and tell me what I 
> am doing wrong?
> 
> Regards,
> Dan
> 
> void myfunction::helloWorldFilter(float *fdata, int xdim, int ydim, int 
> zdim,
>                                       int numiter, QApplication *app)
> {
> 
> // 
> // ***********************************************************************
> //          Preliminaries to read the array into an ITK Image class *
> // ***********************************************************************
> //
>   typedef float PixelType;
>   const unsigned int Dimension = 3;
>   typedef itk::Image< PixelType, Dimension > ImageType;
>   typedef itk::ImportImageFilter< PixelType, Dimension >   
> ImportFilterType;  
>   ImportFilterType::Pointer importer = ImportFilterType::New();       
>  
>   ImportFilterType::SizeType  size;
>   size[0]  = xdim;  // size along X
>   size[1]  = ydim;  // size along Y
>   size[2]  = zdim;  // size along Z
> 
>   ImportFilterType::IndexType start;
>   start[0]=0;
>   start[1]=0;
>   start[2]=0;
> 
>   ImportFilterType::RegionType region;
>   region.SetIndex( start );
>   region.SetSize(  size  );
>   importer->SetRegion( region );
>  
>   double origin[ Dimension ];
>   origin[0] = 0.0;    // X coordinate
>   origin[1] = 0.0;    // Y coordinate
>   origin[2] = 0.0;    // Z coordinate
>   importer->SetOrigin( origin );
>  
>   double spacing[ Dimension ];
>   spacing[0] = 1.0;    // along X direction
>   spacing[1] = 1.0;    // along Y direction
>   spacing[2] = 1.0;    // along Z direction
>   importer->SetSpacing( spacing );
> 
>   const bool importFilterWillDeleteTheInputBuffer = false;
>   PixelType * pixeldata = static_cast< PixelType * >( fdata );
>   const unsigned int numberOfPixels =  size[0] * size[1] * size[2];
>  
>   importer->SetImportPointer( pixeldata, numberOfPixels,
>                                   importFilterWillDeleteTheInputBuffer );
>   importer->Update();
> 
> // ****************************************************************
> //                      End preliminaries                                *
> // ****************************************************************
> //
> //                    THRESHOLDING EXAMPLE
> 
> typedef itk::ThresholdImageFilter< ImageType >  FilterType;
> FilterType::Pointer filter = FilterType::New();
> filter->SetInput( importer->GetOutput() );
> filter->ThresholdBelow( 180 );
> filter->Update();
> //
> // **************************************************************
> //                          End Filter                                    *
> // **************************************************************
> //
> // **************************************************************
> //                              Write back to array                   *
> // **************************************************************
> ImageType::PixelContainer * container;
> container = filter->GetOutput()->GetPixelContainer();
> container->SetContainerManageMemory( false );
> fdata = container->GetImportPointer();
> //
> //
> }
> 
> 
> 
> Best Regards,
> Dan
> Daniel R Einstein, PhD
> Biological Monitoring and Modeling
> Pacific Northwest National Laboratory
> P.O. Box 999; MSIN P7-59
> Richland, WA 99352
> Tel: 509/ 376-2924
> Fax: 509/376-9064
> _daniel.einstein at pnl.gov_ <mailto:daniel.einstein at pnl.gov>
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users



More information about the Insight-users mailing list