static void WriteImage(const ImageType::Pointer image, const std::string& fileName);
static void CreateImage(ImageType::Pointer image);
int main(int argc, char *argv[])
{
ImageType::Pointer image = ImageType::New();
if( argc == 2)
{
ImageReader::Pointer reader = ImageReader::New();
std::string fileName = argv[1];
reader->SetFileName(fileName);
reader->Update();
image = reader->GetOutput();
}
else
{
CreateImage(image);
WriteImage(image, "input.png");
}
BinaryThinningImageFilterType::Pointer binaryThinningImageFilter = BinaryThinningImageFilterType::New();
binaryThinningImageFilter->SetInput(image);
binaryThinningImageFilter->Update();
RescaleType::Pointer rescaler = RescaleType::New();
rescaler->SetInput( binaryThinningImageFilter->GetOutput() );
rescaler->SetOutputMinimum(0);
rescaler->SetOutputMaximum(255);
rescaler->Update();
WriteImage(rescaler->GetOutput(), "output.png");
return EXIT_SUCCESS;
}
void CreateImage(ImageType::Pointer image)
{
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
for(unsigned int i = 20; i < 80; ++i)
{
for(unsigned int j = 50; j < 55; ++j)
{
index[0] = i;
index[1] = j;
image->SetPixel(index, 255);
}
}
}
void WriteImage(const ImageType::Pointer image, const std::string& fileName)
{
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(fileName);
writer->SetInput(image);
writer->Update();
}