21 #ifndef otbWaveletsBandsListToWaveletsSynopsisImageFilter_hxx
22 #define otbWaveletsBandsListToWaveletsSynopsisImageFilter_hxx
25 #include "itkImageRegionIterator.h"
26 #include "itkImageRegionConstIterator.h"
28 #include "itkProgressReporter.h"
33 template <
class TImageList,
class TImage>
39 template <
class TImageList,
class TImage>
47 template <
class TImageList,
class TImage>
52 if (this->GetOutput())
54 if (this->GetInput()->Size() > 0)
57 typename InputImageType::Pointer lastBand = this->GetInput()->Back();
60 RegionType largestBandRegion = lastBand->GetLargestPossibleRegion();
63 typename RegionType::SizeType outputSize = largestBandRegion.GetSize();
66 outputSize[0] *= m_DecimationRatio;
67 outputSize[1] *= m_DecimationRatio;
70 RegionType outputLargestRegion;
71 outputLargestRegion.SetSize(outputSize);
74 this->GetOutput()->CopyInformation(lastBand);
75 this->GetOutput()->SetLargestPossibleRegion(outputLargestRegion);
82 template <
class TImageList,
class TImage>
85 typename InputImageListType::Pointer inputPtr = this->GetInput();
86 typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
87 while (inputListIt != inputPtr->End())
89 inputListIt.Get()->SetRequestedRegionToLargestPossibleRegion();
98 template <
class TImageList,
class TImage>
100 itk::ThreadIdType threadId)
103 typename InputImageListType::Pointer inputPtr = this->GetInput();
104 typename OutputImageType::Pointer outputPtr = this->GetOutput();
108 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
111 typedef itk::ImageRegionConstIterator<InputImageType> InputIteratorType;
112 typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType;
115 typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
116 unsigned int bandIndex = 0;
119 unsigned int numberOfDecompositionLevels = (inputPtr->Size() - 1) / 3;
122 typename RegionType::SizeType largestSize = outputPtr->GetLargestPossibleRegion().GetSize();
125 for (; inputListIt != inputPtr->End(); ++inputListIt, ++bandIndex)
128 typename RegionType::OffsetType currentOffset;
129 currentOffset.Fill(0);
132 unsigned int currentLevel = 0;
133 unsigned int currentSubBand = 0;
138 currentLevel = 1 + (bandIndex - 1) / 3;
139 currentSubBand = (bandIndex - 1) % 3;
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);
146 if (currentSubBand == 0)
148 currentOffset[0] += offsetX;
150 else if (currentSubBand == 1)
152 currentOffset[1] += offsetY;
156 currentOffset[0] += offsetX;
157 currentOffset[1] += offsetY;
161 RegionType currentBandRegion = inputListIt.Get()->GetLargestPossibleRegion();
164 RegionType currentOutputRegion = currentBandRegion;
165 typename RegionType::IndexType currentOutputIndex = currentBandRegion.GetIndex();
166 currentOutputIndex += currentOffset;
167 currentOutputRegion.SetIndex(currentOutputIndex);
172 if (currentOutputRegion.Crop(outputRegionForThread))
175 RegionType currentInputRegion = currentBandRegion;
176 currentOutputIndex = currentOutputRegion.GetIndex();
177 typename RegionType::IndexType currentInputIndex = currentBandRegion.GetIndex();
179 for (
unsigned int i = 0; i < InputImageType::ImageDimension; ++i)
181 currentInputIndex[i] += currentOutputIndex[i];
182 currentInputIndex[i] -= currentOffset[i];
184 currentInputRegion.SetSize(currentOutputRegion.GetSize());
185 currentInputRegion.SetIndex(currentInputIndex);
187 InputIteratorType inIt(inputListIt.Get(), currentInputRegion);
188 OutputIteratorType outIt(outputPtr, currentOutputRegion);
195 while (!inIt.IsAtEnd() && !outIt.IsAtEnd())
198 outIt.Set(
static_cast<typename OutputImageType::InternalPixelType
>(inIt.Get()));
202 progress.CompletedPixel();