template <typename TImage>
static void CreateImage(TImage* const image);
int main( int argc, char *argv[])
{
typedef unsigned char PixelType;
typedef unsigned short LabelType;
std::string fileName;
InputImageType::Pointer image;
if( argc < 2 )
{
image = InputImageType::New();
CreateImage(image.GetPointer());
fileName = "Generated image";
}
else
{
fileName = argv[1];
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(fileName);
reader->Update();
image = reader->GetOutput();
}
ConnectedComponentImageFilterType;
I2LType;
ConnectedComponentImageFilterType::Pointer connected =
ConnectedComponentImageFilterType::New ();
connected->SetInput(image);
connected->Update();
I2LType::Pointer i2l = I2LType::New();
i2l->SetInput( connected->GetOutput() );
i2l->SetComputePerimeter(true);
i2l->Update();
LabelMapType *labelMap = i2l->GetOutput();
std::cout << "File " << "\"" << fileName << "\""
<< " has " << labelMap->GetNumberOfLabelObjects() << " labels." << std::endl;
for (unsigned int n = 0; n < labelMap->GetNumberOfLabelObjects(); ++n)
{
ShapeLabelObjectType *labelObject = labelMap->GetNthLabelObject(n);
std::cout << "Label: "
std::cout << " BoundingBox: "
<< labelObject->GetBoundingBox() << std::endl;
std::cout << " NumberOfPixels: "
<< labelObject->GetNumberOfPixels() << std::endl;
std::cout << " PhysicalSize: "
<< labelObject->GetPhysicalSize() << std::endl;
std::cout << " Centroid: "
<< labelObject->GetCentroid() << std::endl;
std::cout << " NumberOfPixelsOnBorder: "
<< labelObject->GetNumberOfPixelsOnBorder() << std::endl;
std::cout << " PerimeterOnBorder: "
<< labelObject->GetPerimeterOnBorder() << std::endl;
std::cout << " FeretDiameter: "
<< labelObject->GetFeretDiameter() << std::endl;
std::cout << " PrincipalMoments: "
<< labelObject->GetPrincipalMoments() << std::endl;
std::cout << " PrincipalAxes: "
<< labelObject->GetPrincipalAxes() << std::endl;
std::cout << " Elongation: "
<< labelObject->GetElongation() << std::endl;
std::cout << " Perimeter: "
<< labelObject->GetPerimeter() << std::endl;
std::cout << " Roundness: "
<< labelObject->GetRoundness() << std::endl;
std::cout << " EquivalentSphericalRadius: "
<< labelObject->GetEquivalentSphericalRadius() << std::endl;
std::cout << " EquivalentSphericalPerimeter: "
<< labelObject->GetEquivalentSphericalPerimeter() << std::endl;
std::cout << " EquivalentEllipsoidDiameter: "
<< labelObject->GetEquivalentEllipsoidDiameter() << std::endl;
std::cout << " Flatness: "
<< labelObject->GetFlatness() << std::endl;
std::cout << " PerimeterOnBorderRatio: "
<< labelObject->GetPerimeterOnBorderRatio() << std::endl;
}
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;
typename TImage::RegionType region(start, size);
image->SetRegions(region);
image->Allocate();
{
{
image->SetPixel(pixelIndex, 255);
}
}
{
{
image->SetPixel(pixelIndex, 255);
}
}
}