[Insight-users] Polygon to Image Exception

Jazz Kartell jazzkartell at gmx.de
Fri Jan 8 14:51:25 EST 2010


Hello,

i want to store a convex hull of an object in an image...
i had a look at: 
http://www.itk.org/pipermail/insight-users/2009-April/029800.html
but i get the following error:

terminate called after throwing an instance of 'itk::ExceptionObject'
   what():  ...../Code/SpatialObject/itkPolygonSpatialObject.txx:426:
non-planar polygon

i don't understand that message, because the dimension of the polygon is 
set to 2, so it should be planar...

perhaps someone could help me?

Thanks in advance and best regards

     //write convex hulls to file
     typedef itk::PolygonSpatialObject<2>  PolygonType;
     PolygonType::Pointer polygon = PolygonType::New();
     PolygonType::PointType point;

     polygon->ComputeObjectToWorldTransform();

         for (int i=0; i< lower_hull.size(); i++){
             std::pair<int,int> p = lower_hull[i];
             point[0]=p.first;
             point[1]=p.second;
             polygon->AddPoint(point);
         }
         for (int i=upper_hull.size()-1; i>=0; i--){
             std::pair<int,int> p = upper_hull[i];
             point[0]=p.first;
             point[1]=p.second;
             polygon->AddPoint(point);
         }

     typedef itk::Image<double, 2> ImageType;
     typedef itk::SpatialObjectToImageFilter< PolygonType, ImageType > 
SpatialObjectToImageFilterType;
     ImageType::Pointer image = ImageType::New();
     SpatialObjectToImageFilterType::Pointer imageFilter =  
SpatialObjectToImageFilterType::New();

     imageFilter->SetInput( polygon );
     imageFilter->SetInsideValue(1);
     imageFilter->SetOutsideValue(0);
     polygon->SetThickness(1.0);

     ImageType::SizeType size;
     size[0] = 500;
     size[1] = 500;
     imageFilter->SetSize(size);

     double origin[2];
     origin[0] = 0.0;
     origin[1] = 0.0;
     imageFilter->SetOrigin(origin);

     double spacing[2];
     spacing[0] = 1.0;
     spacing[1] = 1.0;
     imageFilter->SetSpacing(spacing);
     imageFilter->Update();

     image = imageFilter->GetOutput();

     typedef itk::ImageFileWriter<ImageType> WriterType;
     WriterType::Pointer w = WriterType::New();

     w->SetInput(image);
     w->SetFileName("/home/bkirchholtes/out.jpg");
     w->Update();


More information about the Insight-users mailing list