Orfeo Toolbox  4.0
otbWaveletTransform.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  Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved.
13  See ITCopyright.txt for details.
14 
15  This software is distributed WITHOUT ANY WARRANTY; without even
16  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17  PURPOSE. See the above copyright notices for more information.
18 
19 =========================================================================*/
20 
21 #ifndef __otbWaveletTransform_txx
22 #define __otbWaveletTransform_txx
23 #include "otbWaveletTransform.h"
24 
25 #include "itkImageRegionIterator.h"
27 #include "itkProgressAccumulator.h"
28 #include "otbMacro.h"
29 
30 namespace otb {
31 
36 template <class TInputImage, class TOutputImage, class TFilter>
39  : m_NumberOfDecompositions(1), m_SubsampleImageFactor(2)
40 {
44  this->SetNthOutput(0, OutputImageListType::New());
45 
46  m_FilterList = FilterListType::New();
47 }
48 
49 template <class TInputImage, class TOutputImage, class TFilter>
50 void
53 {
55  progress->SetMiniPipelineFilter(this);
56 
57  GetFilterList()->Resize(GetNumberOfDecompositions());
58 
59  this->GetFilterList()->SetNthElement(0, FilterType::New());
60  FilterPointerType filter = this->GetFilterList()->GetNthElement(0); //GetNthFilter( 0 );
61  filter->SetInput(this->GetInput());
62  filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
63 
64  otbMsgDevMacro(<<"Allocating " << (1 + GetNumberOfDecompositions() * (filter->GetNumberOfOutputs() - 1)) << " output\n");
65  this->GetOutput()->Resize(
66  1 + GetNumberOfDecompositions() * (filter->GetNumberOfOutputs() - 1));
67 
68  otbMsgDevMacro(<<"Using " << this->GetOutput()->Size() << " outputs...");
69  for (unsigned int idx = 0; idx < this->GetOutput()->Size(); ++idx)
70  {
71  this->GetOutput()->SetNthElement(idx, OutputImageType::New());
72  }
73 
74  progress->RegisterInternalFilter(filter,
75  1.f / static_cast<float>(GetNumberOfDecompositions()));
76 
77  filter->Update();
78 
79  for (unsigned int idx = 1; idx < filter->GetNumberOfOutputs(); ++idx)
80  {
81  this->GetOutput()->SetNthElement(
82  this->GetOutput()->Size() - filter->GetNumberOfOutputs() + idx,
83  filter->GetOutput(idx));
84  }
85 
86  for (unsigned int nbDecomp = 1; nbDecomp < GetNumberOfDecompositions(); nbDecomp++)
87  {
88  this->GetFilterList()->SetNthElement(nbDecomp, FilterType::New());
89  filter = this->GetFilterList()->GetNthElement(nbDecomp); //this->GetNthFilter( nbDecomp );
90  filter->SetInput(this->GetNthFilter(nbDecomp - 1)->GetOutput(0));
91  filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
92  if (GetSubsampleImageFactor() == 1) filter->SetUpSampleFilterFactor(nbDecomp + 1);
93 
94  progress->RegisterInternalFilter(filter,
95  1.f / static_cast<float>(GetNumberOfDecompositions()));
96  filter->Update();
97 
98  for (unsigned int idx = 1; idx < filter->GetNumberOfOutputs(); ++idx)
99  {
100  this->GetOutput()->SetNthElement(
101  this->GetOutput()->Size() - 1 - (nbDecomp + 1) * (filter->GetNumberOfOutputs() - 1) + idx,
102  filter->GetOutput(idx));
103  }
104  }
105 
106  this->GetOutput()->SetNthElement(0, filter->GetOutput(0));
107 }
108 
113 template <class TInputImage, class TOutputImage, class TFilter>
116  : m_NumberOfDecompositions(1), m_SubsampleImageFactor(2)
117 {
118  this->SetNumberOfRequiredInputs(1);
119  this->SetNumberOfRequiredInputs(1);
121  this->SetNthOutput(0, OutputImageType::New());
122 
123  m_FilterList = FilterListType::New();
124 }
125 
126 template <class TInputImage, class TOutputImage, class TFilter>
127 void
130 {
131  this->GetOutput()->CopyInformation(this->GetInput()->GetNthElement(0));
132 
133  if (GetSubsampleImageFactor() != 1)
134  {
135  InputImageRegionType inputRegion = this->GetInput()->GetNthElement(0)->GetLargestPossibleRegion();
136  SizeType inputSize = inputRegion.GetSize();
137  IndexType inputIndex = inputRegion.GetIndex();
138 
139  OutputImageSizeType outputSize;
140  OutputImageIndexType outputIndex;
141 
142  for (unsigned int i = 0; i < InputImageDimension; ++i)
143  {
144  outputIndex[i] = inputIndex[i] * GetSubsampleImageFactor() * GetNumberOfDecompositions();
145  outputSize[i] = inputSize[i] * GetSubsampleImageFactor() * GetNumberOfDecompositions();
146  }
147 
148  OutputImageRegionType outputRegion;
149  outputRegion.SetIndex(outputIndex);
150  outputRegion.SetSize(outputSize);
151 
152  this->GetOutput()->SetRegions(outputRegion);
153  }
154 }
155 
156 template <class TInputImage, class TOutputImage, class TFilter>
157 void
160 {
161  FilterPointerType filter = FilterType::New();
162 
163  const unsigned int filterbankInputSize = 1 << InputImageDimension;
164 
165  m_NumberOfDecompositions = (this->GetInput()->Size() - 1)/(filterbankInputSize - 1);
166 
167  otbMsgDevMacro(<< "Found " << m_NumberOfDecompositions << " decompositions");
168 
170  progress->SetMiniPipelineFilter(this);
171 
172  this->GetFilterList()->Resize(GetNumberOfDecompositions());
173 
174  InputImageIterator inputIterator = this->GetInput()->Begin();
175 
176  this->GetFilterList()->SetNthElement(0, FilterType::New());
177  filter = this->GetNthFilter(0);
178  for (unsigned int i = 0; i < filterbankInputSize; ++i)
179  {
180  filter->SetInput(i, inputIterator.Get());
181  ++inputIterator;
182  }
183 
184  filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
185  if (GetSubsampleImageFactor() == 1)
186  {
187  filter->SetUpSampleFilterFactor(GetNumberOfDecompositions());
188  }
189 
190  progress->RegisterInternalFilter(filter,
191  1.f / static_cast<float>(GetNumberOfDecompositions()));
192  filter->Update();
193 
194  for (unsigned int idx = 1; idx < GetNumberOfDecompositions(); ++idx)
195  {
196  this->GetFilterList()->SetNthElement(idx, FilterType::New());
197  filter = this->GetNthFilter(idx);
198  filter->SetInput(0, this->GetNthFilter(idx - 1)->GetOutput());
199 
200  for (unsigned int i = 1; i < filterbankInputSize; ++i)
201  {
202  filter->SetInput(i, inputIterator.Get());
203  ++inputIterator;
204  }
205 
206  filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
207  if (GetSubsampleImageFactor() == 1)
208  {
209  filter->SetUpSampleFilterFactor(GetNumberOfDecompositions() - idx);
210  }
211 
212  progress->RegisterInternalFilter(filter,
213  1.f / static_cast<float>(GetNumberOfDecompositions()));
214  filter->Update();
215  }
216 
217  // This step is necessary to transtype output image to the wanted format
218  this->GetOutput()->CopyInformation(filter->GetOutput());
219  this->GetOutput()->SetRegions(filter->GetOutput()->GetLargestPossibleRegion());
220  this->GetOutput()->Allocate();
221  this->GetOutput()->FillBuffer(0);
222 
224  (this->GetOutput(), this->GetOutput()->GetLargestPossibleRegion());
226  (filter->GetOutput(), filter->GetOutput()->GetLargestPossibleRegion());
227 
228  for (outputIter.GoToBegin(), outFltIter.GoToBegin(); !outputIter.IsAtEnd(); ++outputIter, ++outFltIter)
229  {
230  outputIter.Set(static_cast<OutputValueType>(outFltIter.Get()));
231  }
232 }
233 
234 } // end of namespace otb
235 
236 #endif

Generated at Sat Mar 8 2014 16:27:05 for Orfeo Toolbox with doxygen 1.8.3.1