Apply Atan Image Filter

Synopsis

Compute the arctangent of each pixel.

Results

Code

C++

#include "itkImage.h"
#include "itkRandomImageSource.h"
#include "itkImageFileWriter.h"
#include "itkAtanImageFilter.h"

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

  constexpr unsigned int Dimension = 2;
  using InputPixelType = unsigned char;

  using InputImageType = itk::Image<InputPixelType, Dimension>;

  InputImageType::SizeType size;
  size.Fill(100);

  using RandomImageSourceType = itk::RandomImageSource<InputImageType>;

  RandomImageSourceType::Pointer randomImageSource = RandomImageSourceType::New();
  randomImageSource->SetNumberOfWorkUnits(1); // to produce non-random results
  randomImageSource->SetSize(size);

  using OutputPixelType = float;
  using OutputImageType = itk::Image<OutputPixelType, Dimension>;

  using FilterType = itk::AtanImageFilter<InputImageType, OutputImageType>;
  FilterType::Pointer filter = FilterType::New();
  filter->SetInput(randomImageSource->GetOutput());

  using WriterType = itk::ImageFileWriter<OutputImageType>;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(argv[1]);
  writer->SetInput(filter->GetOutput());

  try
  {
    writer->Update();
  }
  catch (itk::ExceptionObject & error)
  {
    std::cerr << "Error: " << error << std::endl;
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

Classes demonstrated

template<typename TInputImage, typename TOutputImage>
class AtanImageFilter : public itk::UnaryGeneratorImageFilter<TInputImage, TOutputImage>

Computes the one-argument inverse tangent of each pixel.

This filter is templated over the pixel type of the input image and the pixel type of the output image.

The filter walks over all the pixels in the input image, and for each pixel does the following:

  • cast the pixel value to double,

  • apply the std::atan() function to the double value,

  • cast the double value resulting from std::atan() to the pixel type of the output image,

  • store the cast value into the output image.

See itk::AtanImageFilter for additional documentation.