#include "itksys/SystemTools.hxx"
#include <sstream>
template <typename TImage>
static void CreateImage(TImage* const image);
int main( int argc, char *argv[])
{
using PixelType = unsigned char;
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();
}
ConnectedComponentImageFilterType::Pointer connected =
ConnectedComponentImageFilterType::New ();
connected->SetInput(image);
connected->Update();
std::cout << "Number of objects: " << connected->GetObjectCount() << std::endl;
RGBFilterType::Pointer rgbFilter = RGBFilterType::New();
rgbFilter->SetInput( connected->GetOutput() );
image.GetPointer(),true,
argc > 1 ? itksys::SystemTools::GetFilenameName(argv[1]) : "Generated image");
std::stringstream desc;
desc << "Connected Components: "
<< connected->GetObjectCount() << " objects";
rgbFilter->GetOutput(),
true,
desc.str());
return EXIT_SUCCESS;
}
template <typename TImage>
void CreateImage(TImage* const image)
{
start[0] = 0;
start[1] = 0;
unsigned int NumRows = 200;
unsigned int NumCols = 300;
size[0] = NumRows;
size[1] = NumCols;
image->SetRegions(region);
image->Allocate();
{
{
image->SetPixel(pixelIndex, 255);
}
}
{
{
image->SetPixel(pixelIndex, 255);
}
}
}