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>;
auto 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>;
auto filter = FilterType::New();
filter->SetInput(randomImageSource->GetOutput());
try
{
itk::WriteImage(filter->GetOutput(), argv[1]);
}
catch (const 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 thedouble
value,cast the
double
value resulting fromstd::atan()
to the pixel type of the output image,store the cast value into the output image.