ITK/Examples/WishList/SpatialObjects/ContourSpatialObject: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
No edit summary
(Deprcated)
 
Line 1: Line 1:
Output image is empty?
{{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/*  pages likely require ITK version 4.13 or earlier releasesIn many cases, the examples on this page no longer conform to the best practices for modern ITK versions.}}
 
==ContourSpatialObject.cxx==
<source lang="cpp">
#include "itkSpatialObjectToImageFilter.h"
#include "itkContourSpatialObject.h"
#include "itkContourSpatialObjectPoint.h"
#include "itkImageFileWriter.h"
 
#include "QuickView.h"
 
int main( int argc, char *argv[] )
{
  typedef unsigned char PixelType;
  const unsigned int Dimension = 2;
 
  typedef itk::Image< PixelType, Dimension >    ImageType;
 
  typedef itk::ContourSpatialObject< Dimension >  ContourType;
 
  typedef itk::SpatialObjectToImageFilter<
    ContourType, ImageType >  SpatialObjectToImageFilterType;
 
 
  // Create a list of points
  ContourType::ControlPointListType points;
 
  // Add some points
  ContourType::ControlPointType point;
  point.SetPosition(0,0);
  points.push_back(point);
   point.SetPosition(0,30);
  points.push_back(point);
  point.SetPosition(30,30);
  points.push_back(point);
  point.SetPosition(0,0);
  points.push_back(point);
 
  // Create a contour from the list of points
  ContourType::Pointer contour = ContourType::New();
  contour->SetControlPoints(points);
 
  SpatialObjectToImageFilterType::Pointer imageFilter =
    SpatialObjectToImageFilterType::New();
  itk::Size<2> size;
  size.Fill(50);
  imageFilter->SetInsideValue(255); // white
  imageFilter->SetSize(size);
  imageFilter->SetInput(contour);
  imageFilter->Update();
 
  QuickView viewer;
  viewer.AddImage(imageFilter->GetOutput());
  viewer.Visualize();
  /*
  typedef itk::ImageFileWriter< ImageType >    WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName("contour.png");
  writer->SetInput( imageFilter->GetOutput() );
  writer->Update();
  */
  return EXIT_SUCCESS;
}
 
</source>
 
{{ITKVTKCMakeLists|{{SUBPAGENAME}}}}

Latest revision as of 23:14, 7 June 2019

Warning: The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.