Skip to content

Instantly share code, notes, and snippets.

@N-Dekker
Last active February 26, 2018 10:22
Show Gist options
  • Save N-Dekker/b276d312dc37958b6657f889f2687ba4 to your computer and use it in GitHub Desktop.
Save N-Dekker/b276d312dc37958b6657f889f2687ba4 to your computer and use it in GitHub Desktop.
Checks that the center of a circle detected by HoughTransform2DCirclesImageFilter is inside the circle, using ITK 4.13
// Author: Niels Dekker, LKEB, Leiden University Medical Center, The Netherlands
//
// Example code from https://discourse.itk.org/t/hough-transform-2d-circles-image-filter-getcircles-patch/350/63
#include <itkHoughTransform2DCirclesImageFilter.h>
#include <itkImage.h>
#include <iostream>
int main()
{
// Create an image with a circle centered at [6, 8]:
enum { centerX = 6, centerY = 8 };
const auto image = itk::Image<unsigned>::New();
image->SetRegions({ 16, 16 });
image->Allocate(true);
image->SetPixel({ centerX, centerY }, 1);
image->SetPixel({ centerX, centerY - 1 }, 1);
image->SetPixel({ centerX, centerY + 1 }, 1);
image->SetPixel({ centerX - 1, centerY }, 1);
image->SetPixel({ centerX + 1, centerY }, 1);
const auto filter =
itk::HoughTransform2DCirclesImageFilter<unsigned, unsigned, double>::New();
filter->SetInput(image);
filter->Update();
// GetCircles() finds a circle of radius 1, centered at [6, 8].
const auto& spatialObject = filter->GetCircles().front();
spatialObject->ComputeObjectToWorldTransform();
const double center[] = { centerX, centerY };
const bool isInside = spatialObject->IsInside(center);
std::cout << (isInside ?
"OK: The center is inside." :
"ERROR: The center is not inside!") << std::endl;
return isInside ? EXIT_SUCCESS : EXIT_FAILURE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment