Binary Min and Max Curvature Flow of Binary Image#

Synopsis#

BinaryMinMaxCurvatureFlow a binary image.

Results#

input image

Input image.#

../../../../_images/BinaryMinMaxCurvatureFlow.png

Output In VTK Window#

Code#

C++#

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkBinaryMinMaxCurvatureFlowImageFilter.h"
#include "itkSubtractImageFilter.h"

#include "itksys/SystemTools.hxx"

#ifdef ENABLE_QUICKVIEW
#  include "QuickView.h"
#endif

int
main(int argc, char * argv[])
{
  if (argc < 2)
  {
    std::cerr << argv[0] << " InputFileName [NumberOfIterations]" << std ::endl;
    return EXIT_FAILURE;
  }

  std::string inputFileName = argv[1];

  unsigned int numberOfIterations = 2;
  if (argc > 2)
  {
    numberOfIterations = std::stoi(argv[2]);
  }

  constexpr unsigned int Dimension = 2;

  using InputPixelType = float;
  using OutputPixelType = float;
  using InputImageType = itk::Image<InputPixelType, Dimension>;
  using OutputImageType = itk::Image<OutputPixelType, Dimension>;

  const auto input = itk::ReadImage<InputImageType>(inputFileName);

  using FilterType = itk::BinaryMinMaxCurvatureFlowImageFilter<InputImageType, OutputImageType>;
  auto filter = FilterType::New();
  filter->SetInput(input);
  filter->SetThreshold(255);
  filter->SetNumberOfIterations(numberOfIterations);

  using SubtractType = itk::SubtractImageFilter<OutputImageType>;
  auto diff = SubtractType::New();
  diff->SetInput1(input);
  diff->SetInput2(filter->GetOutput());

#ifdef ENABLE_QUICKVIEW
  QuickView viewer;
  viewer.AddImage(input.GetPointer(), true, itksys::SystemTools::GetFilenameName(inputFileName));

  std::stringstream desc;
  desc << "BinaryMinMaxCurvature, iterations = " << numberOfIterations;
  viewer.AddImage(filter->GetOutput(), true, desc.str());

  std::stringstream desc2;
  desc2 << "Original - BinaryMinMaxCurvatureFlow";
  viewer.AddImage(diff->GetOutput(), true, desc2.str());

  viewer.Visualize();
#endif

  return EXIT_SUCCESS;
}

Classes demonstrated#

template<typename TInputImage, typename TOutputImage>
class BinaryMinMaxCurvatureFlowImageFilter : public itk::MinMaxCurvatureFlowImageFilter<TInputImage, TOutputImage>

Denoise a binary image using min/max curvature flow.

BinaryMinMaxCurvatureFlowImageFilter implements a curvature driven image denoising algorithm. This filter assumes that the image is essentially binary: consisting of two classes. Iso-brightness contours in the input image are viewed as a level set. The level set is then evolved using a curvature-based speed function:

I_t = F_{\mbox{minmax}} |\nabla I|

where F_{\mbox{minmax}} = \min(\kappa,0) if \mbox{Avg}_{\mbox{stencil}}(x) is less than or equal to T_{threshold} and \max(\kappa,0), otherwise. \kappa is the mean curvature of the iso-brightness contour at point x.

In min/max curvature flow, movement is turned on or off depending on the scale of the noise one wants to remove. Switching depends on the average image value of a region of radius R around each point. The choice of R, the stencil radius, governs the scale of the noise to be removed.

The threshold value T_{threshold} is a user specified value which discriminates between the two pixel classes.

This filter make use of the multi-threaded finite difference solver hierarchy. Updates are computed using a BinaryMinMaxCurvatureFlowFunction object. A zero flux Neumann boundary condition is used when computing derivatives near the data boundary.

Reference: “Level Set Methods and Fast Marching Methods”, J.A. Sethian, Cambridge Press, Chapter 16, Second edition, 1999.

Warning

This filter assumes that the input and output types have the same dimensions. This filter also requires that the output image pixels are of a real type. This filter works for any dimensional images.

See

BinaryMinMaxCurvatureFlowFunction

See

CurvatureFlowImageFilter

See

MinMaxCurvatureFlowImageFilter

ITK Sphinx Examples:

See itk::BinaryMinMaxCurvatureFlowImageFilter for additional documentation.