ITK/Examples/Segmentation/ContourExtractor2DImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Created page with "==ContourExtractor2DImageFilter.cxx== <source lang="cpp"> #include "itkImage.h" #include "itkImageFileWriter.h" #include "itkContourExtractor2DImageFilter.h" typedef itk::Image...")
 
(Deprecated content that is moved to sphinx)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==ContourExtractor2DImageFilter.cxx==
{{warning|1=The media wiki content on this page is no longer maintainedThe 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.}}
<source lang="cpp">
#include "itkImage.h"
#include "itkImageFileWriter.h"
#include "itkContourExtractor2DImageFilter.h"
   
typedef itk::Image<unsigned char, 2>  ImageType;
static void CreateImage(ImageType::Pointer image);
int main(int, char *[])
{
  ImageType::Pointer image = ImageType::New();
  CreateImage(image);
  typedef itk::ContourExtractor2DImageFilter <ImageType>
          ContourExtractor2DImageFilterType;
  ContourExtractor2DImageFilterType::Pointer contourExtractor2DImageFilter
          = ContourExtractor2DImageFilterType::New();
  contourExtractor2DImageFilter->SetInput(image);
  //contourExtractor2DImageFilter->SetContourValue(255);
  contourExtractor2DImageFilter->SetContourValue(0);
  contourExtractor2DImageFilter->Update();
  ContourExtractor2DImageFilterType::VertexListType::ConstIterator vertexIterator = contourExtractor2DImageFilter->GetOutput()->GetVertexList()->Begin();
 
  while(vertexIterator != contourExtractor2DImageFilter->GetOutput()->GetVertexList()->End())
    {
    std::cout << vertexIterator->Value() << std::endl;
    ++vertexIterator;
    }
 
  return EXIT_SUCCESS;
}
   
void CreateImage(ImageType::Pointer image)
{
  // Create an image
  ImageType::IndexType start;
  start.Fill(0);
  ImageType::SizeType size;
  size.Fill(100);
   ImageType::RegionType region(start, size);
  image->SetRegions(region);
  image->Allocate();
  image->FillBuffer(0);
 
  // Create a line of white pixels
  for(unsigned int i = 40; i < 60; ++i)
    {
    ImageType::IndexType pixel;
    pixel.Fill(i);
    image->SetPixel(pixel, 255);
    }
   
  typedef  itk::ImageFileWriter< ImageType  > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName("image.png");
  writer->SetInput(image);
  writer->Update();
}
 
</source>
 
{{ITKCMakeLists|ContourExtractor2DImageFilter}}

Latest revision as of 15:26, 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.