OTB  9.0.0
Orfeo Toolbox
otbSubsampleImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  * Copyright (C) 2007-2012 Institut Mines Telecom / Telecom Bretagne
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 
23 #ifndef otbSubsampleImageFilter_hxx
24 #define otbSubsampleImageFilter_hxx
26 
27 #include "otbMacro.h"
29 #include "itkImageRegionIterator.h"
30 #include "itkProgressReporter.h"
31 
32 namespace otb
33 {
34 
35 template <class TInputImage, class TOutputImage, Wavelet::WaveletDirection TDirectionOfTransformation>
37 {
38  Superclass::PrintSelf(os, indent);
39  os << indent << "SubsampleFactor = [" << m_SubsampleFactor[0];
40  for (unsigned int i = 1; i < InputImageDimension; ++i)
41  {
42  os << ", " << m_SubsampleFactor[i];
43  }
44  os << "]\n";
45 }
46 
47 template <class TInputImage, class TOutputImage, Wavelet::WaveletDirection TDirectionOfTransformation>
49 {
50  for (unsigned int i = 0; i < InputImageDimension; ++i)
51  {
52  if (m_SubsampleFactor[i] != 1)
53  return false;
54  }
55 
56  return true;
57 }
58 
59 template <class TInputImage, class TOutputImage, Wavelet::WaveletDirection TDirectionOfTransformation>
61 {
62  Superclass::GenerateOutputInformation();
63 
64  if (!IsSubsampleFactorOne())
65  {
66  OutputImageRegionType newRegion;
67  this->CallCopyInputRegionToOutputRegion(newRegion, this->GetInput()->GetLargestPossibleRegion());
68  this->GetOutput()->SetRegions(newRegion);
69  }
70 }
71 
72 template <class TInputImage, class TOutputImage, Wavelet::WaveletDirection TDirectionOfTransformation>
74  const OutputImageRegionType& srcRegion)
75 {
76  Superclass::CallCopyOutputRegionToInputRegion(destRegion, srcRegion);
77 
78  if (DirectionOfTransformation == Wavelet::INVERSE)
79  {
80  typename OutputImageRegionType::IndexType srcIndex = srcRegion.GetIndex();
81  typename OutputImageRegionType::SizeType srcSize = srcRegion.GetSize();
82 
83  typename InputImageRegionType::IndexType destIndex;
84  typename InputImageRegionType::SizeType destSize;
85 
86  for (unsigned int i = 0; i < InputImageDimension; ++i)
87  {
88  // TODO: This seems not right in odd index cases
89  destIndex[i] = srcIndex[i] / m_SubsampleFactor[i];
90  destSize[i] = srcSize[i] / m_SubsampleFactor[i];
91  }
92 
93  destRegion.SetIndex(destIndex);
94  destRegion.SetSize(destSize);
95  }
96 }
97 
98 template <class TInputImage, class TOutputImage, Wavelet::WaveletDirection TDirectionOfTransformation>
100  const InputImageRegionType& srcRegion)
101 {
102  Superclass::CallCopyInputRegionToOutputRegion(destRegion, srcRegion);
103 
104  if (DirectionOfTransformation == Wavelet::INVERSE)
105  {
106  typename InputImageRegionType::IndexType srcIndex = srcRegion.GetIndex();
107  typename InputImageRegionType::SizeType srcSize = srcRegion.GetSize();
108 
109  typename OutputImageRegionType::IndexType destIndex;
110  typename OutputImageRegionType::SizeType destSize;
111 
112  for (unsigned int i = 0; i < InputImageDimension; ++i)
113  {
114  destIndex[i] = srcIndex[i] * m_SubsampleFactor[i];
115  destSize[i] = srcSize[i] * m_SubsampleFactor[i];
116  }
117 
118  destRegion.SetIndex(destIndex);
119  destRegion.SetSize(destSize);
120  }
121 }
122 
123 template <class TInputImage, class TOutputImage, Wavelet::WaveletDirection TDirectionOfTransformation>
125 {
126  OutputImagePointerType output = this->GetOutput();
127  output->FillBuffer(0);
128 }
129 
130 template <class TInputImage, class TOutputImage, Wavelet::WaveletDirection TDirectionOfTransformation>
132  itk::ThreadIdType itkNotUsed(threadId))
133 {
134  OutputImagePointerType output = this->GetOutput();
135 
136  SubsampledImageRegionIterator<OutputImageType> outputIter(this->GetOutput(), outputRegionForThread);
137  outputIter.SetSubsampleFactor(1);
138  outputIter.GoToBegin();
139 
140  InputImageRegionType inputRegionForThread;
141  this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
142 
143  SubsampledImageRegionConstIterator<InputImageType> inputIter(this->GetInput(), inputRegionForThread);
144 
145  if (DirectionOfTransformation == Wavelet::FORWARD)
146  {
147  inputIter.SetSubsampleFactor(GetSubsampleFactor());
148  inputIter.GoToBegin();
149 
150  while (!inputIter.IsAtEnd())
151  {
152  outputIter.SetOffset(static_cast<typename SubsampledImageRegionIterator<OutputImageType>::OffsetType>(inputIter.GetOffset()));
153  outputIter.Set(static_cast<OutputPixelType>(inputIter.Get()));
154  ++inputIter;
155  }
156  }
157  else
158  {
159  inputIter.SetSubsampleFactor(1);
160  inputIter.GoToBegin();
161 
162  while (!inputIter.IsAtEnd())
163  {
164  InputImageIndexType inputIndex = inputIter.GetIndex();
165  OutputImageIndexType outputIndex;
166  for (unsigned int i = 0; i < OutputImageDimension; ++i)
167  {
168  outputIndex[i] = inputIndex[i] * m_SubsampleFactor[i];
169  }
170  outputIter.SetIndex(outputIndex);
171  outputIter.Set(static_cast<OutputPixelType>(inputIter.Get()));
172  ++inputIter;
173  }
174  }
175 }
176 
177 } // end of namespace otb
178 
179 #endif
otb::SubsampledImageRegionConstIterator::SetSubsampleFactor
void SetSubsampleFactor(IndexValueType factor)
Definition: otbSubsampledImageRegionConstIterator.hxx:99
otb::Wavelet::INVERSE
@ INVERSE
Definition: otbWaveletOperatorBase.h:39
otbSubsampledImageRegionIterator.h
otb::SubsampleImageFilter::CallCopyInputRegionToOutputRegion
void CallCopyInputRegionToOutputRegion(OutputImageRegionType &destRegion, const InputImageRegionType &srcRegion) override
Definition: otbSubsampleImageFilter.hxx:99
otb::SubsampleImageFilter::OutputImagePointerType
OutputImageType::Pointer OutputImagePointerType
Definition: otbSubsampleImageFilter.h:85
otbSubsampleImageFilter.h
otb::SubsampleImageFilter::InputImageRegionType
InputImageType::RegionType InputImageRegionType
Definition: otbSubsampleImageFilter.h:80
otb::SubsampledImageRegionConstIterator::GoToBegin
void GoToBegin()
Definition: otbSubsampledImageRegionConstIterator.hxx:132
otb::SubsampledImageRegionIterator::OffsetType
Superclass::OffsetType OffsetType
Definition: otbSubsampledImageRegionIterator.h:62
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::SubsampleImageFilter::OutputImageIndexType
OutputImageType::IndexType OutputImageIndexType
Definition: otbSubsampleImageFilter.h:88
otbMacro.h
otb::SubsampleImageFilter::CallCopyOutputRegionToInputRegion
void CallCopyOutputRegionToInputRegion(InputImageRegionType &destRegion, const OutputImageRegionType &srcRegion) override
Definition: otbSubsampleImageFilter.hxx:73
otb::SubsampledImageRegionConstIterator::GetOffset
OffsetType GetOffset() const
Definition: otbSubsampledImageRegionConstIterator.h:229
otb::SubsampleImageFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbSubsampleImageFilter.hxx:36
otb::SubsampleImageFilter::OutputPixelType
OutputImageType::PixelType OutputPixelType
Definition: otbSubsampleImageFilter.h:89
otb::SubsampleImageFilter::InputImageIndexType
InputImageType::IndexType InputImageIndexType
Definition: otbSubsampleImageFilter.h:81
otb::SubsampledImageRegionConstIterator::GetIndex
IndexType GetIndex() const
Definition: otbSubsampledImageRegionConstIterator.h:172
otb::SubsampledImageRegionIterator
Regular subsample iterator over an image.
Definition: otbSubsampledImageRegionIterator.h:46
otb::SubsampledImageRegionConstIterator::IsAtEnd
bool IsAtEnd(void) const
Definition: otbSubsampledImageRegionConstIterator.h:161
otb::SubsampleImageFilter::IsSubsampleFactorOne
bool IsSubsampleFactorOne() const
Definition: otbSubsampleImageFilter.hxx:48
otb::SubsampledImageRegionIterator::Set
void Set(const PixelType &value) const
Definition: otbSubsampledImageRegionIterator.h:89
otb::Wavelet::FORWARD
@ FORWARD
Definition: otbWaveletOperatorBase.h:38
otb::SubsampleImageFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbSubsampleImageFilter.h:86
otb::SubsampledImageRegionConstIterator
Regular subsample iterator over an image.
Definition: otbSubsampledImageRegionConstIterator.h:44
otb::SubsampledImageRegionConstIterator::SetOffset
void SetOffset(const OffsetType &offset)
Definition: otbSubsampledImageRegionConstIterator.hxx:181
otb::SubsampleImageFilter::ThreadedGenerateData
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override
Definition: otbSubsampleImageFilter.hxx:131
otb::SubsampleImageFilter::GenerateOutputInformation
void GenerateOutputInformation() override
Definition: otbSubsampleImageFilter.hxx:60
otb::SubsampledImageRegionConstIterator::SetIndex
void SetIndex(const IndexType &ind) override
Definition: otbSubsampledImageRegionConstIterator.hxx:151
otb::SubsampleImageFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData() override
Definition: otbSubsampleImageFilter.hxx:124