OTB  10.0.0
Orfeo Toolbox
otbDecimateImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 {
108  InputImageRegionType inputRegionForThread;
109  this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
110 
111  SubsampledImageRegionConstIterator<InputImageType> decimationIterator(this->GetInput(), inputRegionForThread);
112  decimationIterator.SetSubsampleFactor(GetDecimationFactor());
113  decimationIterator.GoToBegin();
114 
115  itk::ImageRegionIterator<InputImageType> outputIter(this->GetOutput(), outputRegionForThread);
116  outputIter.GoToBegin();
117 
118  while (!decimationIterator.IsAtEnd() && !outputIter.IsAtEnd())
119  {
120  outputIter.Set(static_cast<OutputPixelType>(decimationIterator.Get()));
121 
122  ++outputIter;
123  ++decimationIterator;
124  }
125 }
126 
127 } // end of namespace otb
128 
129 #endif
typename InputImageType::RegionType InputImageRegionType
void CallCopyInputRegionToOutputRegion(OutputImageRegionType &destRegion, const InputImageRegionType &srcRegion) override
void CallCopyOutputRegionToInputRegion(InputImageRegionType &destRegion, const OutputImageRegionType &srcRegion) override
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
void PrintSelf(std::ostream &os, itk::Indent indent) const override
typename OutputImageType::RegionType OutputImageRegionType
typename OutputImageType::PixelType OutputPixelType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
#define otbGenericMsgDebugMacro(x)
Definition: otbMacro.h:115