#include <list>
int
main(int argc, char * argv[])
{
if (argc < 6)
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0] << std::endl;
std::cerr << " inputImage " << std::endl;
std::cerr << " outputImage" << std::endl;
std::cerr << " numberOfCircles " << std::endl;
std::cerr << " radius Min " << std::endl;
std::cerr << " radius Max " << std::endl;
std::cerr << " sweep Angle (default = 0)" << std::endl;
std::cerr << " SigmaGradient (default = 1) " << std::endl;
std::cerr << " variance of the accumulator blurring (default = 5) "
<< std::endl;
std::cerr
<< " radius of the disk to remove from the accumulator (default = 10) "
<< std::endl;
return EXIT_FAILURE;
}
using PixelType = unsigned char;
using AccumulatorPixelType = unsigned int;
using RadiusPixelType = float;
reader->SetFileName(argv[1]);
try
{
reader->Update();
}
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
return EXIT_FAILURE;
}
std::cout << "Computing Hough Map" << std::endl;
using HoughTransformFilterType =
AccumulatorPixelType,
RadiusPixelType>;
houghFilter->SetInput(reader->GetOutput());
houghFilter->SetNumberOfCircles(std::stoi(argv[3]));
houghFilter->SetMinimumRadius(std::stod(argv[4]));
houghFilter->SetMaximumRadius(std::stod(argv[5]));
if (argc > 6)
{
houghFilter->SetSweepAngle(std::stod(argv[6]));
}
if (argc > 7)
{
houghFilter->SetSigmaGradient(std::stoi(argv[7]));
}
if (argc > 8)
{
houghFilter->SetVariance(std::stod(argv[8]));
}
if (argc > 9)
{
houghFilter->SetDiscRadiusRatio(std::stod(argv[9]));
}
houghFilter->Update();
houghFilter->GetOutput();
HoughTransformFilterType::CirclesListType circles;
circles = houghFilter->GetCircles();
std::cout << "Found " << circles.size() << " circle(s)." << std::endl;
using OutputPixelType = unsigned char;
region.
SetSize(localImage->GetLargestPossibleRegion().GetSize());
region.SetIndex(localImage->GetLargestPossibleRegion().GetIndex());
localOutputImage->SetRegions(region);
localOutputImage->SetOrigin(localImage->GetOrigin());
localOutputImage->SetSpacing(localImage->GetSpacing());
localOutputImage->Allocate(true);
using CirclesListType = HoughTransformFilterType::CirclesListType;
CirclesListType::const_iterator itCircles = circles.begin();
while (itCircles != circles.end())
{
std::cout << "Center: ";
std::cout << (*itCircles)->GetCenterInObjectSpace() << std::endl;
std::cout << "Radius: " << (*itCircles)->GetRadiusInObjectSpace()[0]
<< std::endl;
{
(*itCircles)->GetCenterInObjectSpace();
localIndex[0] = itk::Math::Round<IndexValueType>(
centerPoint[0] +
(*itCircles)->GetRadiusInObjectSpace()[0] * std::cos(angle));
localIndex[1] = itk::Math::Round<IndexValueType>(
centerPoint[1] +
(*itCircles)->GetRadiusInObjectSpace()[0] * std::sin(angle));
localOutputImage->GetLargestPossibleRegion();
if (outputRegion.IsInside(localIndex))
{
localOutputImage->SetPixel(localIndex, 255);
}
}
itCircles++;
}
writer->SetFileName(argv[2]);
writer->SetInput(localOutputImage);
try
{
writer->Update();
}
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}