ITK  4.13.0
Insight Segmentation and Registration Toolkit
WikiExamples/Segmentation/SimpleContourExtractorImageFilter.cxx
#include "itkImage.h"
typedef itk::Image<unsigned char, 2> UnsignedCharImageType;
static void CreateImage(UnsignedCharImageType::Pointer image);
int main(int, char *[])
{
UnsignedCharImageType::Pointer image = UnsignedCharImageType::New();
CreateImage(image);
SimpleContourExtractorImageFilterType;
SimpleContourExtractorImageFilterType::Pointer contourFilter
= SimpleContourExtractorImageFilterType::New();
contourFilter->SetInput(image);
contourFilter->Update();
WriterType::Pointer writer = WriterType::New();
writer->SetFileName("output.png");
writer->SetInput(contourFilter->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}
void CreateImage(UnsignedCharImageType::Pointer image)
{
// Create an image
start.Fill(0);
size.Fill(100);
itk::ImageRegion<2> region(start,size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
// Create a line pixels
for(unsigned int i = 40; i < 60; ++i)
{
pixel.Fill(i);
image->SetPixel(pixel, 255);
}
// Create another line of pixels
for(unsigned int i = 10; i < 20; ++i)
{
pixel[0] = 10;
pixel[1] = i;
image->SetPixel(pixel, 255);
}
WriterType::Pointer writer = WriterType::New();
writer->SetFileName("input.png");
writer->SetInput(image);
writer->Update();
}