Zero-crossing Based Edge Decor#

Synopsis#

A zero-crossing based edge detecor

Results#

../../../../_images/Yinyang18.png

Input image.#

../../../../_images/ZeroCrossingBasedEdgeDecor.png

Output In VTK Window#

Code#

C++#

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkZeroCrossingBasedEdgeDetectionImageFilter.h"

#include "itksys/SystemTools.hxx"

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

int
main(int argc, char * argv[])
{
  // Verify command line arguments
  if (argc < 2)
  {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " inputImageFile" << std::endl;
    return EXIT_FAILURE;
  }

  double var = 5.0;
  if (argc > 2)
  {
    var = std::stod(argv[2]);
  }

  // Parse command line arguments
  std::string inputFileName = argv[1];

  // Setup types
  using FloatImageType = itk::Image<float, 2>;
  using FilterType = itk::ZeroCrossingBasedEdgeDetectionImageFilter<FloatImageType, FloatImageType>;

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

  // Create and setup a derivative filter
  auto edgeDetector = FilterType::New();
  edgeDetector->SetInput(input);
  FilterType::ArrayType variance;
  variance.Fill(var);
  edgeDetector->SetVariance(variance);

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

  std::stringstream desc;
  desc << "ZeroBasedEdgeDetection, variance = " << edgeDetector->GetVariance();
  viewer.AddImage(edgeDetector->GetOutput(), true, desc.str());

  viewer.Visualize();
#endif
  return EXIT_SUCCESS;
}

Classes demonstrated#

template<typename TInputImage, typename TOutputImage>
class ZeroCrossingBasedEdgeDetectionImageFilter : public itk::ImageToImageFilter<TInputImage, TOutputImage>

This filter implements a zero-crossing based edge detecor.

The zero-crossing based edge detector looks for pixels in the Laplacian of an image where the value of the Laplacian passes through zero points where the Laplacian changes sign. Such points often occur at “edges” in images i.e. points where the intensity of the image changes rapidly, but they also occur at places that are not as easy to associate with edges. It is best to think of the zero crossing detector as some sort of feature detector rather than as a specific edge detector.

Zero crossings always lie on closed contours and so the output from the zero crossing detector is usually a binary image with single pixel thickness lines showing the positions of the zero crossing points.

In this implementation, the input image is first smoothed with a Gaussian filter, then the LaplacianImageFilter is applied to smoothed image. Finally the zero-crossing of the Laplacian of the smoothed image is detected. The output is a binary image.

Inputs and Outputs

The input to the filter should be a scalar, itk::Image of arbitrary dimension. The output image is a binary, labeled image. See itkZeroCrossingImageFilter for more information on requirements of the data type of the output.

To use this filter, first set the parameters (variance and maximum error) needed by the embedded DiscreteGaussianImageFilter, i.e. See DiscreteGaussianImageFilter for information about these parameters. Optionally, you may also set foreground and background values for the zero-crossing filter. The default label values are Zero for the background and One for the foreground, as defined in NumericTraits for the data type of the output image.

See

DiscreteGaussianImageFilter

See

LaplacianImageFilter

See

ZeroCrossingImageFilter

ITK Sphinx Examples:

See itk::ZeroCrossingBasedEdgeDetectionImageFilter for additional documentation.