int
main(int argc, char * argv[])
{
if (argc < 3)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImageFile outputImageFile" << std::endl;
return EXIT_FAILURE;
}
using InputPixelType = unsigned char;
using OutputPixelType = unsigned char;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName(argv[1]);
writer->SetFileName(argv[2]);
using FilterType =
FilterType::Pointer relabeler = FilterType::New();
relabeler->SetInput(reader->GetOutput());
writer->SetInput(relabeler->GetOutput());
writer->Update();
using SizesInPixelsType = std::vector<itk::SizeValueType>;
const SizesInPixelsType & sizesInPixels =
relabeler->GetSizeOfObjectsInPixels();
auto sizeItr = sizesInPixels.begin();
auto sizeEnd = sizesInPixels.end();
std::cout << "Number of pixels per class " << std::endl;
unsigned int kclass = 0;
while (sizeItr != sizeEnd)
{
std::cout << "Class " << kclass << " = " << *sizeItr << std::endl;
++kclass;
++sizeItr;
}
using SizesInPhysicalUnitsType = std::vector<float>;
const SizesInPhysicalUnitsType sizesInUnits =
relabeler->GetSizeOfObjectsInPhysicalUnits();
auto physicalSizeItr = sizesInUnits.begin();
auto physicalSizeEnd = sizesInUnits.end();
std::cout << "Area in Physical Units per class " << std::endl;
unsigned int jclass = 0;
while (physicalSizeItr != physicalSizeEnd)
{
std::cout << "Class " << jclass << " = " << *physicalSizeItr << std::endl;
++jclass;
++physicalSizeItr;
}
return EXIT_SUCCESS;
}