#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;
constexpr unsigned int Dimension = 2;
ImageType::IndexType localIndex;
ImageType::Pointer localImage;
try
{
}
{
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>;
auto houghFilter = HoughTransformFilterType::New();
houghFilter->SetInput(localImage);
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();
const AccumulatorImageType::Pointer localAccumulator =
houghFilter->GetOutput();
HoughTransformFilterType::CirclesListType circles;
circles = houghFilter->GetCircles();
std::cout << "Found " << circles.size() << " circle(s)." << std::endl;
using OutputPixelType = unsigned char;
auto localOutputImage = OutputImageType::New();
OutputImageType::RegionType region;
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;
{
const HoughTransformFilterType::CircleType::PointType centerPoint =
(*itCircles)->GetCenterInObjectSpace();
using IndexValueType = ImageType::IndexType::IndexValueType;
centerPoint[0] +
(*itCircles)->GetRadiusInObjectSpace()[0] * std::cos(angle));
centerPoint[1] +
(*itCircles)->GetRadiusInObjectSpace()[0] * std::sin(angle));
const OutputImageType::RegionType outputRegion =
localOutputImage->GetLargestPossibleRegion();
if (outputRegion.IsInside(localIndex))
{
localOutputImage->SetPixel(localIndex, 255);
}
}
++itCircles;
}
try
{
}
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Standard exception handling object.
Templated n-dimensional image class.
static constexpr double twopi
static constexpr double pi
TInput TInput TReturn Round(TInput x)
ITK_TEMPLATE_EXPORT void WriteImage(TImagePointer &&image, const std::string &filename, bool compress=false)
TOutputImage::Pointer ReadImage(const std::string &filename)