Apply Exp Negative Image Filter#

Synopsis#

Compute exp(-K x) of each pixel.

Results#

Input image

Input image#

Output image

Output image#

Code#

C++#

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkExpNegativeImageFilter.h"

int
main(int argc, char * argv[])
{
  if (argc != 4)
  {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0];
    std::cerr << " <InputFileName> <OutputFileName> <K: ExpNegative parameter>";
    std::cerr << std::endl;
    return EXIT_FAILURE;
  }

  const char * inputFileName = argv[1];
  const char * outputFileName = argv[2];
  const double k = std::stod(argv[3]);

  constexpr unsigned int Dimension = 2;
  using PixelType = float;
  using ImageType = itk::Image<PixelType, Dimension>;

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

  using FilterType = itk::ExpNegativeImageFilter<ImageType, ImageType>;
  auto filter = FilterType::New();
  filter->SetInput(input);
  filter->SetFactor(k);

  try
  {
    itk::WriteImage(filter->GetOutput(), outputFileName);
  }
  catch (const itk::ExceptionObject & error)
  {
    std::cerr << "Error: " << error << std::endl;
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

Python#

#!/usr/bin/env python

import itk
import argparse

parser = argparse.ArgumentParser(description="Apply Exp Negative Image Filter.")
parser.add_argument("input_image")
parser.add_argument("output_image")
parser.add_argument("k", help="ExpNegative parameter.", type=float)
args = parser.parse_args()

Dimension = 2
PixelType = itk.F
ImageType = itk.Image[PixelType, Dimension]

reader = itk.ImageFileReader[ImageType].New()
reader.SetFileName(args.input_image)

expFilter = itk.ExpNegativeImageFilter[ImageType, ImageType].New()
expFilter.SetInput(reader.GetOutput())
expFilter.SetFactor(args.k)

writer = itk.ImageFileWriter[ImageType].New()
writer.SetFileName(args.output_image)
writer.SetInput(expFilter.GetOutput())

writer.Update()

Classes demonstrated#

template<typename TInputImage, typename TOutputImage>
class ExpNegativeImageFilter : public itk::UnaryFunctorImageFilter<TInputImage, TOutputImage, Functor::ExpNegative<TInputImage::PixelType, TOutputImage::PixelType>>

Computes the function exp(-K.x) for each input pixel.

Every output pixel is equal to std::exp(-K.x ). where x is the intensity of the homologous input pixel, and K is a user-provided constant.

See itk::ExpNegativeImageFilter for additional documentation.