Find Higher Derivatives of Image#

Synopsis#

Find higher derivatives of an image.

Results#

input image

Input image.#

VTK Window

Output In VTK Window#

Code#

C++#

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkRecursiveGaussianImageFilter.h"

#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;
  }

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

  // Setup types
  using FloatImageType = itk::Image<float, 2>;
  using UnsignedCharImageType = itk::Image<unsigned char, 2>;

  using filterType = itk::RecursiveGaussianImageFilter<UnsignedCharImageType, FloatImageType>;

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

  // Create and setup a gaussian filter
  auto gaussianFilter = filterType::New();
  gaussianFilter->SetInput(input);
  gaussianFilter->SetDirection(0); // "x" axis
  gaussianFilter->SetSecondOrder();

#ifdef ENABLE_QUICKVIEW
  QuickView viewer;
  viewer.AddImage<UnsignedCharImageType>(input);
  viewer.AddImage<FloatImageType>(gaussianFilter->GetOutput());
  viewer.Visualize();
#endif

  return EXIT_SUCCESS;
}

Classes demonstrated#

template<typename TInputImage, typename TOutputImage = TInputImage>
class RecursiveGaussianImageFilter : public itk::RecursiveSeparableImageFilter<TInputImage, TOutputImage>

Base class for computing IIR convolution with an approximation of a Gaussian kernel.

\frac{ 1 }{ \sigma \sqrt{ 2 \pi } } \exp{ \left( - \frac{x^2}{ 2 \sigma^2 } \right) }

RecursiveGaussianImageFilter is the base class for recursive filters that approximate convolution with the Gaussian kernel. This class implements the recursive filtering method proposed by R.Deriche in IEEE-PAMI Vol.12, No.1, January 1990, pp 78-87, “Fast Algorithms for Low-Level Vision”

Details of the implementation are described in the technical report: R. Deriche, “Recursively Implementing The Gaussian and Its Derivatives”, INRIA, 1993, ftp://ftp.inria.fr/INRIA/tech-reports/RR/RR-1893.ps.gz

Further improvements of the algorithm are described in: G. Farnebäck & C.-F. Westin, “Improving Deriche-style Recursive Gaussian

Filters”. J

Math Imaging Vis 26, 293–299 (2006). https://doi.org/10.1007/s10851-006-8464-z

As compared to itk::DiscreteGaussianImageFilter, this filter tends to be faster for large kernels, and it can take the derivative of the blurred image in one step. Also, note that we have itk::RecursiveGaussianImageFilter::SetSigma(), but itk::DiscreteGaussianImageFilter::SetVariance().

See

DiscreteGaussianImageFilter

ITK Sphinx Examples:

See itk::RecursiveGaussianImageFilter for additional documentation.