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

  using ReaderType = itk::ImageFileReader<ImageType>;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(inputFileName);

  using FilterType = itk::ExpNegativeImageFilter<ImageType, ImageType>;
  FilterType::Pointer filter = FilterType::New();
  filter->SetInput(reader->GetOutput());
  filter->SetFactor(k);

  using WriterType = itk::ImageFileWriter<ImageType>;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(outputFileName);
  writer->SetInput(filter->GetOutput());
  try
  {
    writer->Update();
  }
  catch (itk::ExceptionObject & error)
  {
    std::cerr << "Error: " << error << std::endl;
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

Python

#!/usr/bin/env python

import itk

if len(sys.argv) != 4:
    print("Usage: " + sys.argv[0] + "<InputFileName> "
          "<InputFileName> <OutputFileName> <K: ExpNegative parameter>")
    sys.exit(1)

inputFileName = sys.argv[1]
outputFileName = sys.argv[2]
k = float(sys.argv[3])

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

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

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

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

writer.Update()

Classes demonstrated