OTB  9.0.0
Orfeo Toolbox
otbWaveletsBandsListToWaveletsSynopsisImageFilter.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 otbWaveletsBandsListToWaveletsSynopsisImageFilter_hxx
22 #define otbWaveletsBandsListToWaveletsSynopsisImageFilter_hxx
23 
25 #include "itkImageRegionIterator.h"
26 #include "itkImageRegionConstIterator.h"
27 #include "otbMacro.h"
28 #include "itkProgressReporter.h"
29 
30 namespace otb
31 {
33 template <class TImageList, class TImage>
35 {
36 }
37 
39 template <class TImageList, class TImage>
41 {
42 }
43 
47 template <class TImageList, class TImage>
49 {
50  // We must set the size of the output image to be twice the size of the last image
51  // of the image list, which is the first band.
52  if (this->GetOutput())
53  {
54  if (this->GetInput()->Size() > 0)
55  {
56  // Retrieve the largest band
57  typename InputImageType::Pointer lastBand = this->GetInput()->Back();
58 
59  // Retrieve the region of the largest band
60  RegionType largestBandRegion = lastBand->GetLargestPossibleRegion();
61 
62  // Retrieve the size of the largest region
63  typename RegionType::SizeType outputSize = largestBandRegion.GetSize();
64 
65  // Multiply this size by two
66  outputSize[0] *= m_DecimationRatio;
67  outputSize[1] *= m_DecimationRatio;
68 
69  // Build the output region
70  RegionType outputLargestRegion;
71  outputLargestRegion.SetSize(outputSize);
72 
73  // Copy information to the output image
74  this->GetOutput()->CopyInformation(lastBand);
75  this->GetOutput()->SetLargestPossibleRegion(outputLargestRegion);
76  }
77  }
78 }
82 template <class TImageList, class TImage>
84 {
85  typename InputImageListType::Pointer inputPtr = this->GetInput();
86  typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
87  while (inputListIt != inputPtr->End())
88  {
89  inputListIt.Get()->SetRequestedRegionToLargestPossibleRegion();
90  ++inputListIt;
91  }
92 }
94 
98 template <class TImageList, class TImage>
100  itk::ThreadIdType threadId)
101 {
102  // Retrieve input and output pointers
103  typename InputImageListType::Pointer inputPtr = this->GetInput();
104  typename OutputImageType::Pointer outputPtr = this->GetOutput();
106 
107  // Set up progress reporting
108  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
109 
110  // defines input and output iterators
111  typedef itk::ImageRegionConstIterator<InputImageType> InputIteratorType;
112  typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType;
113 
114  // Set up an iterator on the input wavelets band
115  typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
116  unsigned int bandIndex = 0;
117 
118  // Compute number of decomposition levels
119  unsigned int numberOfDecompositionLevels = (inputPtr->Size() - 1) / 3;
120 
121  // Retrieve the largest possible region size
122  typename RegionType::SizeType largestSize = outputPtr->GetLargestPossibleRegion().GetSize();
123 
124  // Iterate on each band
125  for (; inputListIt != inputPtr->End(); ++inputListIt, ++bandIndex)
126  {
127  // Build a band offset
128  typename RegionType::OffsetType currentOffset;
129  currentOffset.Fill(0);
130 
131  // Initialise Current level
132  unsigned int currentLevel = 0;
133  unsigned int currentSubBand = 0;
134 
135  if (bandIndex > 0)
136  {
137  // Compute current level and sub band
138  currentLevel = 1 + (bandIndex - 1) / 3;
139  currentSubBand = (bandIndex - 1) % 3;
140 
141  // Compute potential offset in x and y
142  unsigned int offsetX = largestSize[0] / (unsigned int)std::pow((double)m_DecimationRatio, (double)1 + numberOfDecompositionLevels - currentLevel);
143  unsigned int offsetY = largestSize[1] / (unsigned int)std::pow((double)m_DecimationRatio, (double)1 + numberOfDecompositionLevels - currentLevel);
144 
145  // Compute final offset according to the subband index
146  if (currentSubBand == 0)
147  {
148  currentOffset[0] += offsetX;
149  }
150  else if (currentSubBand == 1)
151  {
152  currentOffset[1] += offsetY;
153  }
154  else
155  {
156  currentOffset[0] += offsetX;
157  currentOffset[1] += offsetY;
158  }
159  }
160  // Retrieve current band region
161  RegionType currentBandRegion = inputListIt.Get()->GetLargestPossibleRegion();
162 
163  // Apply offset to get the current output region
164  RegionType currentOutputRegion = currentBandRegion;
165  typename RegionType::IndexType currentOutputIndex = currentBandRegion.GetIndex();
166  currentOutputIndex += currentOffset;
167  currentOutputRegion.SetIndex(currentOutputIndex);
168 
169  // Crop with the outputRegionForThread. If the crop fails,
170  // it means that currentOutputRegion is outside of outputRegionForThread,
171  // and in this case we skip to the next image in the list.
172  if (currentOutputRegion.Crop(outputRegionForThread))
173  {
174  // Compute the corresponding input region
175  RegionType currentInputRegion = currentBandRegion;
176  currentOutputIndex = currentOutputRegion.GetIndex();
177  typename RegionType::IndexType currentInputIndex = currentBandRegion.GetIndex();
178 
179  for (unsigned int i = 0; i < InputImageType::ImageDimension; ++i)
180  {
181  currentInputIndex[i] += currentOutputIndex[i];
182  currentInputIndex[i] -= currentOffset[i];
183  }
184  currentInputRegion.SetSize(currentOutputRegion.GetSize());
185  currentInputRegion.SetIndex(currentInputIndex);
186 
187  InputIteratorType inIt(inputListIt.Get(), currentInputRegion);
188  OutputIteratorType outIt(outputPtr, currentOutputRegion);
189 
190  // Go to begin
191  inIt.GoToBegin();
192  outIt.GoToBegin();
193 
194  // Copy pixels
195  while (!inIt.IsAtEnd() && !outIt.IsAtEnd())
196  {
197  // Copy pixel value
198  outIt.Set(static_cast<typename OutputImageType::InternalPixelType>(inIt.Get()));
199  // Step forward
200  ++inIt;
201  ++outIt;
202  progress.CompletedPixel();
203  }
204  }
205  }
206 }
otb::WaveletsBandsListToWaveletsSynopsisImageFilter::~WaveletsBandsListToWaveletsSynopsisImageFilter
virtual ~WaveletsBandsListToWaveletsSynopsisImageFilter()
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbMacro.h
otb::WaveletsBandsListToWaveletsSynopsisImageFilter::ThreadedGenerateData
virtual void ThreadedGenerateData(const RegionType &outputRegionForThread, itk::ThreadIdType threadId) override
otbWaveletsBandsListToWaveletsSynopsisImageFilter.h
otb::WaveletsBandsListToWaveletsSynopsisImageFilter::WaveletsBandsListToWaveletsSynopsisImageFilter
WaveletsBandsListToWaveletsSynopsisImageFilter()
otb::WaveletsBandsListToWaveletsSynopsisImageFilter::GenerateInputRequestedRegion
virtual void GenerateInputRequestedRegion(void) override
otb::WaveletsBandsListToWaveletsSynopsisImageFilter::GenerateOutputInformation
virtual void GenerateOutputInformation(void) override