OTB  9.0.0
Orfeo Toolbox
otbForwardFourierMellinTransformImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbForwardFourierMellinTransformImageFilter_hxx
22 #define otbForwardFourierMellinTransformImageFilter_hxx
23 
25 #include "itkImageDuplicator.h"
26 
27 namespace otb
28 {
29 template <class TPixel, class TInterpol, unsigned int Dimension>
31 {
32 
33  m_Sigma = 1.0;
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;
42 }
43 
44 template <class TPixel, class TInterpol, unsigned int Dimension>
46 {
47  Superclass::GenerateOutputInformation();
48 
49  OutputImagePointer outputPtr = this->GetOutput();
50 
51  if (!outputPtr)
52  {
53  return;
54  }
55  typename OutputImageType::RegionType largestPossibleRegion;
56  typename OutputImageType::IndexType index;
57  index.Fill(0);
58  largestPossibleRegion.SetIndex(index);
59  largestPossibleRegion.SetSize(m_OutputSize);
60  outputPtr->SetLargestPossibleRegion(largestPossibleRegion);
61 }
62 
63 template <class TPixel, class TInterpol, unsigned int Dimension>
65 {
66  ImagePointer input = const_cast<InputImageType*>(this->GetInput());
67  input->SetRequestedRegion(input->GetLargestPossibleRegion());
68 }
69 
70 template <class TPixel, class TInterpol, unsigned int Dimension>
72 {
73  typename LogPolarTransformType::ParametersType params(4);
74 
75  // Compute centre of the transform
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]);
81  PointType centrePt;
82  this->GetInput()->TransformContinuousIndexToPhysicalPoint(centre, centrePt);
83 
84  // Compute physical radius in the input image
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);
87 
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);
93 
94  // Compute rho scaling parameter in index space
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];
97 
98  // log polar resampling
99  m_ResampleFilter->SetInput(this->GetInput());
100  m_ResampleFilter->SetDefaultPixelValue(m_DefaultPixelValue);
101  m_ResampleFilter->SetSize(m_OutputSize);
102 
103  PointType outOrigin;
104  outOrigin.Fill(0.5);
105  m_ResampleFilter->SetOutputOrigin(outOrigin);
106  SpacingType outSpacing;
107  outSpacing.Fill(1.0);
108  m_ResampleFilter->SetOutputSpacing(outSpacing);
109 
110  m_ResampleFilter->Update();
111 
112  typename InputImageType::Pointer tempImage = m_ResampleFilter->GetOutput();
113  IteratorType iter(tempImage, tempImage->GetRequestedRegion());
114 
115  // Min/max values of the output pixel type AND these values
116  // represented as the output type of the interpolator
117  const PixelType minOutputValue = itk::NumericTraits<PixelType>::NonpositiveMin();
118  const PixelType maxOutputValue = itk::NumericTraits<PixelType>::max();
119 
120  // Normalization is specific to FourierMellin convergence conditions, and
121  // thus should be implemented here instead of in the resample filter.
122  for (iter.GoToBegin(); !iter.IsAtEnd(); ++iter)
123  {
124  // 0.5 shift in order to follow output image physical space
125  double Rho = (0.5 + static_cast<double>(iter.GetIndex()[1])) * rhoScaleIndex;
126  PixelType pixval;
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);
131 
132  if (value < minOutputValue)
133  {
134  pixval = minOutputValue;
135  }
136  else if (value > maxOutputValue)
137  {
138  pixval = maxOutputValue;
139  }
140  else
141  {
142  pixval = static_cast<PixelType>(value);
143  }
144  iter.Set(pixval);
145  }
146  m_FFTFilter->SetInput(tempImage);
147 
148  m_FFTFilter->GraftOutput(this->GetOutput());
149  m_FFTFilter->Update();
150  this->GraftOutput(m_FFTFilter->GetOutput());
151 }
otb::ForwardFourierMellinTransformImageFilter::GenerateInputRequestedRegion
void GenerateInputRequestedRegion(void) override
otb::ForwardFourierMellinTransformImageFilter::ForwardFourierMellinTransformImageFilter
ForwardFourierMellinTransformImageFilter()
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbForwardFourierMellinTransformImageFilter.h
otb::ForwardFourierMellinTransformImageFilter::GenerateOutputInformation
void GenerateOutputInformation(void) override
otb::ForwardFourierMellinTransformImageFilter::GenerateData
void GenerateData() override