namespace
{
}
static void CreateImage(ImageType* const image);
int main(int argc, char *argv[])
{
ImageType::Pointer image;
if(argc == 1)
{
image = ImageType::New();
CreateImage(image);
}
else
{
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
reader->Update();
image = reader->GetOutput();
}
unsigned int radius = 5;
if (argc == 3)
{
std::stringstream ss(argv[2]);
ss >> radius;
}
std::cout << "Radius: " << radius << std::endl;
StructuringElementType;
StructuringElementType structuringElement;
structuringElement.CreateStructuringElement();
BinaryMorphologicalOpeningImageFilterType;
BinaryMorphologicalOpeningImageFilterType::Pointer openingFilter
= BinaryMorphologicalOpeningImageFilterType::New();
openingFilter->SetInput(image);
openingFilter->SetKernel(structuringElement);
openingFilter->Update();
SubtractType::Pointer diff = SubtractType::New();
diff->SetInput1(image);
diff->SetInput2(openingFilter->GetOutput());
std::stringstream desc;
desc << "Original ";
true,
desc.str());
std::stringstream desc2;
desc2 << "BinaryOpening, radius = " << radius;
viewer.
AddImage(openingFilter->GetOutput(),
true,
desc2.str());
std::stringstream desc3;
desc3 << "Original - BinaryOpening";
true,
desc3.str());
return EXIT_SUCCESS;
}
void CreateImage(ImageType* const image)
{
unsigned int NumRows = 200;
unsigned int NumCols = 300;
size[0] = NumRows;
size[1] = NumCols;
image->SetRegions(region);
image->Allocate();
for(unsigned int r = 40; r < 100; r++)
{
for(unsigned int c = 40; c < 100; c++)
{
pixelIndex[0] = r;
pixelIndex[1] = c;
image->SetPixel(pixelIndex, 50);
}
}
}