[Insight-users] pointSet to Image

Luis Ibanez luis.ibanez at kitware.com
Sun, 25 Apr 2004 09:48:21 -0400


Hi David:

Doxygen may help:
http://www.itk.org/Insight/Doxygen/html/classitk_1_1PointSetToImageFilter.html

You are missing to specify all the information
regarding the geometrical characteristics of
the image to be generated as output.

In particular you missed:

    SetSize()
    SetSpacing()
    SetOrigin()
    SetInsideValue()   // gray level for the points
    SetOutsideValue()  // gray level for the background


---

Note also that in your example you are not
allocating memory for the PointSet when you
are converting the input Image into a PointSet.
Please look at the SoftwareGuide for details
on how to Allocate() memory for the points.


Regards


     Luis


-----------------------------
David Macias Verde wrote:

> Hi:
> 
> Could anyone tell what is the problem I have when converting a pointset
> to an image with the PointSetToImage class? I attached below my code.
> 
> I have converted an image to a pointset and then going back to an image.
> 
> Thanks,
> 
> David Macias-Verde
> 
> 
> 
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> 
> 
> #include "itkImage.h"
> #include "itkPointSet.h"
> #include "itkImageRegionConstIterator.h"
> #include "itkPointSetToImageFilter.h" 
> #include "itkImageFileWriter.h"
> 
> 
> int main( int argc, const char * argv[] )
> {
>   
>   if( argc < 2 )
>     {
>     std::cerr << "Usage: " << std::endl;
>     std::cerr << argv[0] << " inputImageFile  " << std::endl;
>     return -1;
>     }
> 
>   typedef unsigned short PixelType;
>   const   unsigned int Dimension = 2;
> 
>   typedef itk::Image< PixelType, Dimension >    ImageType;
> 
>   typedef itk::PointSet< PixelType, Dimension > PointSetType;
> 
>   typedef itk::ImageFileReader< ImageType >  ReaderType;
> 
>   ReaderType::Pointer reader = ReaderType::New();
> 
>   const char * inputFilename  = argv[1];
>   reader->SetFileName( inputFilename  );
> 
>   try 
>     { 
>     reader->Update(); 
>     } 
>   catch( itk::ExceptionObject & err ) 
>     { 
>     std::cout << "ExceptionObject caught !" << std::endl; 
>     std::cout << err << std::endl; 
>     return -1;
>     } 
> 
>   PointSetType::Pointer  pointSet = PointSetType::New();
> 
> 
>   typedef itk::ImageRegionConstIterator< ImageType > IteratorType;
> 
>   const ImageType * image = reader->GetOutput();
> 
>   IteratorType it( image, image->GetBufferedRegion() );
> 
>   it.GoToBegin();
> 
>   typedef PointSetType::PointType     PointType;
>   PointType point;
> 
>   unsigned long pointId = 0;
> 
>   while( !it.IsAtEnd() )
>     {
>     image->TransformIndexToPhysicalPoint( it.GetIndex() , point );
>     pointSet->SetPoint( pointId, point );
>     pointSet->SetPointData( pointId, it.Get() );
>     ++it;
>     ++pointId;
>     }
>    
>   typedef itk::PointSetToImageFilter <PointSetType, ImageType>
> FilterType;
>   
>   FilterType::Pointer finalImage = FilterType::New();
>     finalImage->SetInput(pointSet);
>    
>   typedef itk::ImageFileWriter <ImageType> WriterType;
>         
>   WriterType::Pointer writer =  WriterType::New();
>    
>    try 
>     { 
>       writer->SetFileName("test.png");
>       writer->SetInput(finalImage->GetOutput());
>       writer->Update();
>     } 
>   catch(itk::ExceptionObject & err) 
>     { 
>     std::cout << "ExceptionObject caught !" << std::endl; 
>     std::cout << err << std::endl; 
>     return -1;
>     }    
> 
> }
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>