Zero-crossing Based Edge Decor


A zero-crossing based edge detecor



Input image.


Output In VTK Window



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

#include "itksys/SystemTools.hxx"

#  include "QuickView.h"

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 ReaderType = itk::ImageFileReader<FloatImageType>;

  using FilterType = itk::ZeroCrossingBasedEdgeDetectionImageFilter<FloatImageType, FloatImageType>;

  // Create and setup a reader
  ReaderType::Pointer reader = ReaderType::New();

  // Create and setup a derivative filter
  FilterType::Pointer edgeDetector = FilterType::New();
  FilterType::ArrayType variance;

  QuickView viewer;
  viewer.AddImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(inputFilename));

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

  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.







ITK Sphinx Examples:

See itk::ZeroCrossingBasedEdgeDetectionImageFilter for additional documentation.