Orfeo Toolbox  4.0
otbForwardFourierMellinTransformImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbForwardFourierMellinTransformImageFilter_txx
19 #define __otbForwardFourierMellinTransformImageFilter_txx
20 
22 #include "itkImageDuplicator.h"
23 
24 namespace otb
25 {
26 template <class TPixel, class TInterpol, unsigned int Dimension>
29 {
30 
31  m_Sigma = 1.0;
32  m_OutputSize.Fill(512);
33  m_FFTFilter = FourierImageFilterType::New();
34  m_Interpolator = InterpolatorType::New();
35  m_Transform = LogPolarTransformType::New();
36  m_ResampleFilter = ResampleFilterType::New();
37  m_ResampleFilter->SetInterpolator(m_Interpolator);
38  m_ResampleFilter->SetTransform(m_Transform);
39  m_DefaultPixelValue = 0;
40 }
41 
42 template <class TPixel, class TInterpol, unsigned int Dimension>
43 void
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>
64 void
67 {
68  typename LogPolarTransformType::ParametersType params(4);
69  // Center the transform
70  params[0] = 0.5 * static_cast<double>(this->GetInput()->GetLargestPossibleRegion().GetSize()[0]);
71  params[1] = 0.5 * static_cast<double>(this->GetInput()->GetLargestPossibleRegion().GetSize()[1]);
72  params[2] = 360. / m_OutputSize[0];
73  params[3] =
74  vcl_log(vcl_sqrt(vcl_pow(static_cast<double>(this->GetInput()->GetLargestPossibleRegion().GetSize()[0]), 2)
75  + vcl_pow(static_cast<double>(this->GetInput()->GetLargestPossibleRegion().GetSize()[1]),
76  2.)) / 2) / m_OutputSize[1];
77  m_Transform->SetParameters(params);
78 
79  // log polar resampling
80  m_ResampleFilter->SetInput(this->GetInput());
81  m_ResampleFilter->SetDefaultPixelValue(m_DefaultPixelValue);
82  m_ResampleFilter->SetSize(m_OutputSize);
83  m_ResampleFilter->Update();
84 
85  typename InputImageType::Pointer tempImage = m_ResampleFilter->GetOutput();
86  m_Iterator = IteratorType(tempImage, tempImage->GetRequestedRegion());
87 
88  // Min/max values of the output pixel type AND these values
89  // represented as the output type of the interpolator
91  const PixelType maxOutputValue = itk::NumericTraits<PixelType>::max();
92 
93  // Normalization is specific to FourierMellin convergence conditions, and
94  // thus should be implemented here instead of in the resample filter.
95  for (m_Iterator.GoToBegin(); !m_Iterator.IsAtEnd(); ++m_Iterator)
96  {
97  double Rho = m_Iterator.GetIndex()[1] * params[3];
98  PixelType pixval;
99  double valueTemp = static_cast<double>(m_Iterator.Get());
100  valueTemp *= vcl_exp(m_Sigma * Rho);
101  valueTemp *= params[3];
102  PixelType value = static_cast<PixelType>(valueTemp);
103 
104  if (value < minOutputValue)
105  {
106  pixval = minOutputValue;
107  }
108  else if (value > maxOutputValue)
109  {
110  pixval = maxOutputValue;
111  }
112  else
113  {
114  pixval = static_cast<PixelType>(value);
115  }
116  m_Iterator.Set(pixval);
117  }
118  m_FFTFilter->SetInput(tempImage);
119 
120  m_FFTFilter->GraftOutput(this->GetOutput());
121  m_FFTFilter->Update();
122  this->GraftOutput(m_FFTFilter->GetOutput());
123 }
127 template <class TPixel, class TInterpol, unsigned int Dimension>
128 void
130 ::PrintSelf(std::ostream& os, itk::Indent indent) const
131 {
132  Superclass::PrintSelf(os, indent);
133 }
134 } // end namespace otb
135 #endif

Generated at Sat Mar 8 2014 15:56:03 for Orfeo Toolbox with doxygen 1.8.3.1