OTB  7.1.0
Orfeo Toolbox
otbDecimateImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 otbDecimateImageFilter_hxx
24 #define otbDecimateImageFilter_hxx
25 
26 #include "otbDecimateImageFilter.h"
27 
28 #include "otbMacro.h"
30 #include "itkImageRegionIterator.h"
31 #include "itkProgressReporter.h"
32 
33 namespace otb
34 {
35 
36 template <class TInputImage, class TOutputImage>
37 void DecimateImageFilter<TInputImage, TOutputImage>::PrintSelf(std::ostream& os, itk::Indent indent) const
38 {
39  Superclass::PrintSelf(os, indent);
40  os << indent << "DecimationFactor = " << m_DecimationFactor << "\n";
41 }
42 
43 template <class TInputImage, class TOutputImage>
45 {
46  Superclass::GenerateOutputInformation();
47 
48  if (GetDecimationFactor() > 1)
49  {
50  this->GetOutput()->CopyInformation(this->GetInput());
51 
52  OutputImageRegionType newRegion;
53  this->CallCopyInputRegionToOutputRegion(newRegion, this->GetInput()->GetLargestPossibleRegion());
54  this->GetOutput()->SetRegions(newRegion);
55 
56  for (unsigned int i = 0; i < OutputImageDimension; ++i)
57  {
58  otbGenericMsgDebugMacro(<< "Image Output size [" << i << "] = " << newRegion.GetSize(i));
59  }
60  }
61 }
62 
63 template <class TInputImage, class TOutputImage>
65 {
66  Superclass::CallCopyOutputRegionToInputRegion(destRegion, srcRegion);
67 
68  typename OutputImageRegionType::IndexType srcIndex = srcRegion.GetIndex();
69  typename OutputImageRegionType::SizeType srcSize = srcRegion.GetSize();
70 
71  typename InputImageRegionType::IndexType destIndex;
72  typename InputImageRegionType::SizeType destSize;
73 
74  for (unsigned int i = 0; i < InputImageDimension; ++i)
75  {
76  destIndex[i] = srcIndex[i] * GetDecimationFactor();
77  destSize[i] = (srcSize[i] - 1) * GetDecimationFactor() + 1;
78  }
79 
80  destRegion.SetIndex(destIndex);
81  destRegion.SetSize(destSize);
82 }
83 
84 template <class TInputImage, class TOutputImage>
86 {
87  Superclass::CallCopyInputRegionToOutputRegion(destRegion, srcRegion);
88 
89  typename InputImageRegionType::IndexType srcIndex = srcRegion.GetIndex();
90  typename InputImageRegionType::SizeType srcSize = srcRegion.GetSize();
91 
92  typename OutputImageRegionType::IndexType destIndex;
93  typename OutputImageRegionType::SizeType destSize;
94 
95  for (unsigned int i = 0; i < InputImageDimension; ++i)
96  {
97  destIndex[i] = srcIndex[i] / GetDecimationFactor();
98  destSize[i] = (srcSize[i] - 1) / GetDecimationFactor() + 1;
99  }
100 
101  destRegion.SetIndex(destIndex);
102  destRegion.SetSize(destSize);
103 }
104 
105 template <class TInputImage, class TOutputImage>
107  itk::ThreadIdType itkNotUsed(threadId))
108 {
109  InputImageRegionType inputRegionForThread;
110  this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
111 
112  SubsampledImageRegionConstIterator<InputImageType> decimationIterator(this->GetInput(), inputRegionForThread);
113  decimationIterator.SetSubsampleFactor(GetDecimationFactor());
114  decimationIterator.GoToBegin();
115 
116  itk::ImageRegionIterator<InputImageType> outputIter(this->GetOutput(), outputRegionForThread);
117  outputIter.GoToBegin();
118 
119  while (!decimationIterator.IsAtEnd() && !outputIter.IsAtEnd())
120  {
121  outputIter.Set(static_cast<OutputPixelType>(decimationIterator.Get()));
122 
123  ++outputIter;
124  ++decimationIterator;
125  }
126 }
127 
128 } // end of namespace otb
129 
130 #endif
itk::Size< Monteverdi_DIMENSION > SizeType
Definition: mvdTypes.h:137
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:133
virtual void CallCopyOutputRegionToInputRegion(InputImageRegionType &destRegion, const OutputImageRegionType &srcRegion)
#define otbGenericMsgDebugMacro(x)
Definition: otbMacro.h:63
OutputImageType::RegionType OutputImageRegionType
Regular subsample iterator over an image.
InputImageType::RegionType InputImageRegionType
virtual void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const
virtual void CallCopyInputRegionToOutputRegion(OutputImageRegionType &destRegion, const InputImageRegionType &srcRegion)