static void CreateImage(UnsignedCharImageType::Pointer image);
int main(int, char *[])
{
UnsignedCharImageType::Pointer image = UnsignedCharImageType::New();
CreateImage(image);
ApproximateSignedDistanceMapImageFilterType::Pointer approximateSignedDistanceMapImageFilter = ApproximateSignedDistanceMapImageFilterType::New();
approximateSignedDistanceMapImageFilter->SetInput(image);
approximateSignedDistanceMapImageFilter->SetInsideValue(255);
approximateSignedDistanceMapImageFilter->SetOutsideValue(0);
approximateSignedDistanceMapImageFilter->Update();
ContourExtractor2DImageFilterType::Pointer contourExtractor2DImageFilter
= ContourExtractor2DImageFilterType::New();
contourExtractor2DImageFilter->SetInput(approximateSignedDistanceMapImageFilter->GetOutput());
contourExtractor2DImageFilter->SetContourValue(0);
contourExtractor2DImageFilter->Update();
std::cout << "There are " << contourExtractor2DImageFilter->GetNumberOfOutputs() << " contours" << std::endl;
for(unsigned int i = 0; i < contourExtractor2DImageFilter->GetNumberOfOutputs(); ++i)
{
std::cout << "Contour " << i << ": " << std::endl;
ContourExtractor2DImageFilterType::VertexListType::ConstIterator vertexIterator =
contourExtractor2DImageFilter->GetOutput(i)->GetVertexList()->Begin();
while(vertexIterator != contourExtractor2DImageFilter->GetOutput(i)->GetVertexList()->End())
{
std::cout << vertexIterator->Value() << std::endl;
++vertexIterator;
}
std::cout << std::endl;
}
return EXIT_SUCCESS;
}
void CreateImage(UnsignedCharImageType::Pointer image)
{
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
for(unsigned int i = 40; i < 60; ++i)
{
image->SetPixel(pixel, 255);
}
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("image.png");
writer->SetInput(image);
writer->Update();
}