using InputPixelType = unsigned char;
OutputImageType::Pointer segmentationAndCustomColorization(InputImageType::Pointer inImage)
{
WatershedFilterType::Pointer watershed = WatershedFilterType::New();
watershed->SetThreshold(0.05);
watershed->SetLevel(0.3);
watershed->SetInput(inImage);
watershed->Update();
LabeledImageType::Pointer image = watershed->GetOutput();
image->DisconnectPipeline();
OutputImageType::Pointer outImage = OutputImageType::New();
outImage->CopyInformation(image);
outImage->SetRegions(image->GetBufferedRegion());
outImage->Allocate(true);
mt->ParallelizeImageRegion<
Dimension>(image->GetBufferedRegion(),
{
for (; !iIt.
IsAtEnd(); ++iIt, ++oIt)
{
OutputPixelType p;
static_assert(
Dimension <= 3,
"Dimension has to be 2 or 3");
{
p.SetElement(d, ind[d]);
}
}
},
nullptr);
return outImage;
}
int main(int argc, char* argv[])
{
if( argc != 3 )
{
std::cerr << "Usage: "<< std::endl;
std::cerr << argv[0];
std::cerr << " <InputFileName>";
std::cerr << " <OutputFileName>" << std::endl;
return EXIT_FAILURE;
}
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(argv[2]);
writer->UseCompressionOn();
try
{
OutputImageType::Pointer outImage = segmentationAndCustomColorization(reader->GetOutput());
writer->SetInput(outImage);
writer->Update();
}
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}