#include "itksys/SystemTools.hxx"
#include <sstream>
typedef unsigned char PixelType;
int main(int argc, char *argv[])
{
unsigned int numberOfThresholds = 1;
if( argc < 2 )
{
CreateImage(image.GetPointer());
}
else
{
reader->SetFileName(argv[1]);
reader->Update();
if (argc > 2)
{
numberOfThresholds = atoi(argv[2]);
}
image = reader->GetOutput();
}
FilterType;
otsuFilter->SetInput(image);
otsuFilter->SetNumberOfThresholds(numberOfThresholds);
otsuFilter->Update();
colormapImageFilter->SetInput(otsuFilter->GetOutput());
image.GetPointer(),true,
argc > 1 ? itksys::SystemTools::GetFilenameName(argv[1]) : "Generated image");
std::stringstream desc;
desc << "Otsu Threshold\n"
<< otsuFilter->GetNumberOfThresholds()
<< " thresholds: ";
FilterType::ThresholdVectorType thresholds = otsuFilter->GetThresholds();
for (unsigned int i = 0; i < thresholds.size(); i++)
{
desc << itk::NumericTraits<FilterType::InputPixelType>::PrintType(thresholds[i]) << " ";
}
colormapImageFilter->GetOutput(),
true,
desc.str());
return EXIT_SUCCESS;
}
{
ImageType::IndexType start;
start.Fill(0);
ImageType::SizeType size;
size.Fill(100);
ImageType::RegionType region;
region.SetSize(size);
region.SetIndex(start);
image->SetRegions(region);
image->Allocate();
}