Does DenseFiniteDifferenceImageFilter perform reinitialization?

Could anyone confirm if DenseFiniteDifferenceImageFilter performs reinitialization on the level set filter? I tried searching the code and mailing list[1], but I cannot find where the DenseFiniteDifferenceImageFilter reinitializes the distance function!

I am implementing a subclass of DenseFiniteDifferenceImageFilter (.h, .hxx). I am using the finite difference hierarchy to solve a level set problem.

Resources:
[1] https://cmake.org/pipermail/insight-users/2012-March/044175.html

Alright, I found the solution!

DenseFiniteDifferenceImageFilter does not perform reinitialization.

Below is some code for anyone coming across the same problem. I get gradient magnitudes in the range 0.5 - 1.5 with this. It runs fast as well.

template< typename TInputImage, typename TOutputImage >
void
YourFilterThatInheritsFromDenseFiniteDifferenceImageFilter< TInputImage, TOutputImage >
::InitializeIteration()
{
  Superclass::InitializeIteration();

  /* Only need to perform reinitialization if we have curvature */
  /* Perform reinitialization */
  m_ReinitializationFilter = ReinitializationFilterType::New();
  m_ReinitializationFilter->SetLevelSetValue(0.0f);
  m_ReinitializationFilter->NarrowBandingOff();
  m_ReinitializationFilter->SetInput(this->GetOutput());
  m_ReinitializationFilter->Update();

  /* Copy output */
  typename TOutputImage::Pointer output = this->GetOutput();

  ImageRegionConstIterator< TOutputImage > reinit( m_ReinitializationFilter->GetOutput(), output->GetRequestedRegion() );
  ImageRegionIterator< TOutputImage >     out( output, output->GetRequestedRegion() );

  while ( !out.IsAtEnd() )
  {
    out.Value() = reinit.Get();
    ++reinit;
    ++out;
  }
}
2 Likes