#include "itksys/SystemTools.hxx"
#include <sstream>
namespace
{
using PixelType = unsigned char;
}
static void CreateImage(ImageType::Pointer image);
int main(int argc, char *argv[])
{
ImageType::Pointer image;
if( argc < 2 )
{
image = ImageType::New();
CreateImage(image.GetPointer());
}
else
{
ReaderType::Pointer reader =
ReaderType::New();
reader->SetFileName(argv[1]);
reader->Update();
image = reader->GetOutput();
}
FilterType::Pointer otsuFilter
= FilterType::New();
otsuFilter->SetInput(image);
otsuFilter->Update();
image.GetPointer(),true,
argc > 1 ? itksys::SystemTools::GetFilenameName(argv[1]) : "Generated image");
std::stringstream desc;
desc << "Otsu Threshold: "
<< itk::NumericTraits<FilterType::InputPixelType>::PrintType(otsuFilter->GetThreshold());
otsuFilter->GetOutput(),
true,
desc.str());
return EXIT_SUCCESS;
}
void CreateImage(ImageType::Pointer image)
{
region.SetIndex(start);
image->SetRegions(region);
image->Allocate();
}