Skip to content

Commit

Permalink
ENH: IsInside(point) made easier, especially for HoughTransform circles
Browse files Browse the repository at this point in the history
Added ComputeObjectToParentTransform() call to EllipseSpatialObject::
SetCenterPoint(point). This will allow users to directly call
circle->IsInside(point) for a circle detected by HoughTransform, without
having to worry about calling ComputeObjectToParentTransform() or
ComputeObjectToWorldTransform() themselves. Added a test.

This commit indirectly also restores a backward compatibility issue introduced
by commit 1722d1e, which replaced
GetObjectToParentTransform()->m_Offset by GetObjectToWorldTransform()->m_Offset
as storage location for the center coordinates. This new commit ensures that
the center coordinates will be placed at both storage locations.

Change-Id: Iff7fc5ba60f3a9bd0ad4165c047930d283fc7c48
  • Loading branch information
N-Dekker committed Mar 2, 2018
1 parent e417902 commit 210ba16
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Expand Up @@ -70,6 +70,7 @@ EllipseSpatialObject<TDimension>::SetCenterPoint(const PointType& point)
originPoint.Fill(0);
// GetModifiableObjectToWorldTransform() never returns nullptr, no need to check.
this->GetModifiableObjectToWorldTransform()->SetOffset(point - originPoint);
this->ComputeObjectToParentTransform();
}

/** Test whether a point is inside or outside the object
Expand Down
Expand Up @@ -28,8 +28,8 @@
static const unsigned int Dimension = 2;


template< typename ImageType >
void CreateCircle( typename ImageType::Pointer image, const unsigned int center[Dimension], double radius )
template< typename ImageType, typename CenterCoordinateType >
void CreateCircle( typename ImageType::Pointer image, const CenterCoordinateType center[Dimension], double radius )
{
typename ImageType::IndexType index = image->GetLargestPossibleRegion().GetIndex();

Expand Down Expand Up @@ -242,6 +242,53 @@ namespace
return success;
}


// Tests that the center of a circle that was created on the input image
// is inside the spatial object produced by GetCircles().
bool Test_Center_IsInside_SpatialObject_from_GetCircles()
{
using PixelType = unsigned;
using ImageType = itk::Image<PixelType>;
const auto image = ImageType::New();
const ImageType::SizeType imageSize = { { 16, 32 } };
image->SetRegions(imageSize);
image->Allocate(true);
const double center[] = { 6.0, 9.0 };
const double radius = 1.0;
CreateCircle<ImageType>(image, center, radius);

using FilterType = itk::HoughTransform2DCirclesImageFilter< PixelType, unsigned, double >;
const auto filter = FilterType::New();
filter->SetInput(image);
filter->Update();

const FilterType::CirclesListType& circles = filter->GetCircles();

if (circles.size() != 1)
{
std::cout << "ERROR: GetCircles() should have found exactly one circle!" << std::endl;
return false;
}

const FilterType::CirclePointer& circle = circles.front();

if (circle == nullptr)
{
std::cout << "ERROR: The circle found by GetCircles() should not be null!" << std::endl;
return false;
}

const bool isInside = circle->IsInside(center);

if (!isInside)
{
std::cout <<
"ERROR: The center of the actual circle should be inside the spacial object of the detected circle!"
<< std::endl;
}
return isInside;
}

}

int itkHoughTransform2DCirclesImageTest( int, char* [] )
Expand Down Expand Up @@ -500,6 +547,7 @@ int itkHoughTransform2DCirclesImageTest( int, char* [] )
success &= Test_GetCircles_should_return_empty_list_when_NumberOfCircles_is_set_to_zero();
success &= Test_GetCircles_should_return_empty_list_when_input_image_is_uniform();
success &= Test_RadiusImage_and_OutputImage_may_have_different_types();
success &= Test_Center_IsInside_SpatialObject_from_GetCircles();

if (success)
{
Expand Down

0 comments on commit 210ba16

Please sign in to comment.