21 #ifndef otbForwardFourierMellinTransformImageFilter_hxx
22 #define otbForwardFourierMellinTransformImageFilter_hxx
25 #include "itkImageDuplicator.h"
29 template <
class TPixel,
class TInterpol,
unsigned int Dimension>
34 m_OutputSize.Fill(512);
35 m_FFTFilter = FourierImageFilterType::New();
36 m_Interpolator = InterpolatorType::New();
37 m_Transform = LogPolarTransformType::New();
38 m_ResampleFilter = ResampleFilterType::New();
39 m_ResampleFilter->SetInterpolator(m_Interpolator);
40 m_ResampleFilter->SetTransform(m_Transform);
41 m_DefaultPixelValue = 0;
44 template <
class TPixel,
class TInterpol,
unsigned int Dimension>
47 Superclass::GenerateOutputInformation();
49 OutputImagePointer outputPtr = this->GetOutput();
55 typename OutputImageType::RegionType largestPossibleRegion;
56 typename OutputImageType::IndexType index;
58 largestPossibleRegion.SetIndex(index);
59 largestPossibleRegion.SetSize(m_OutputSize);
60 outputPtr->SetLargestPossibleRegion(largestPossibleRegion);
63 template <
class TPixel,
class TInterpol,
unsigned int Dimension>
66 ImagePointer input =
const_cast<InputImageType*
>(this->GetInput());
67 input->SetRequestedRegion(input->GetLargestPossibleRegion());
70 template <
class TPixel,
class TInterpol,
unsigned int Dimension>
73 typename LogPolarTransformType::ParametersType params(4);
76 SizeType inputSize = this->GetInput()->GetLargestPossibleRegion().GetSize();
77 SpacingType inputSpacing = this->GetInput()->GetSignedSpacing();
78 itk::ContinuousIndex<double, 2> centre;
79 centre[0] = -0.5 + 0.5 *
static_cast<double>(inputSize[0]);
80 centre[1] = -0.5 + 0.5 *
static_cast<double>(inputSize[1]);
82 this->GetInput()->TransformContinuousIndexToPhysicalPoint(centre, centrePt);
85 double radius = std::log(
86 std::sqrt(std::pow(
static_cast<double>(inputSize[0]) * inputSpacing[0], 2.0) + std::pow(
static_cast<double>(inputSize[1]) * inputSpacing[1], 2.0)) / 2.0);
88 params[0] = centrePt[0];
89 params[1] = centrePt[1];
90 params[2] = 360. / m_OutputSize[0];
91 params[3] = radius / m_OutputSize[1];
92 m_Transform->SetParameters(params);
95 double rhoScaleIndex =
96 std::log(std::sqrt(std::pow(
static_cast<double>(inputSize[0]), 2.0) + std::pow(
static_cast<double>(inputSize[1]), 2.0)) / 2.0) / m_OutputSize[1];
99 m_ResampleFilter->SetInput(this->GetInput());
100 m_ResampleFilter->SetDefaultPixelValue(m_DefaultPixelValue);
101 m_ResampleFilter->SetSize(m_OutputSize);
105 m_ResampleFilter->SetOutputOrigin(outOrigin);
106 SpacingType outSpacing;
107 outSpacing.Fill(1.0);
108 m_ResampleFilter->SetOutputSpacing(outSpacing);
110 m_ResampleFilter->Update();
112 typename InputImageType::Pointer tempImage = m_ResampleFilter->GetOutput();
113 IteratorType iter(tempImage, tempImage->GetRequestedRegion());
117 const PixelType minOutputValue = itk::NumericTraits<PixelType>::NonpositiveMin();
118 const PixelType maxOutputValue = itk::NumericTraits<PixelType>::max();
122 for (iter.GoToBegin(); !iter.IsAtEnd(); ++iter)
125 double Rho = (0.5 +
static_cast<double>(iter.GetIndex()[1])) * rhoScaleIndex;
127 double valueTemp =
static_cast<double>(iter.Get());
128 valueTemp *= std::exp(m_Sigma * Rho);
129 valueTemp *= rhoScaleIndex;
130 PixelType value =
static_cast<PixelType
>(valueTemp);
132 if (value < minOutputValue)
134 pixval = minOutputValue;
136 else if (value > maxOutputValue)
138 pixval = maxOutputValue;
142 pixval =
static_cast<PixelType
>(value);
146 m_FFTFilter->SetInput(tempImage);
148 m_FFTFilter->GraftOutput(this->GetOutput());
149 m_FFTFilter->Update();
150 this->GraftOutput(m_FFTFilter->GetOutput());