OTB  9.0.0
Orfeo Toolbox
otbDecimateImageFilter.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 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
otb::SubsampledImageRegionConstIterator::SetSubsampleFactor
void SetSubsampleFactor(IndexValueType factor)
Definition: otbSubsampledImageRegionConstIterator.hxx:99
otbSubsampledImageRegionConstIterator.h
otb::DecimateImageFilter::CallCopyOutputRegionToInputRegion
virtual void CallCopyOutputRegionToInputRegion(InputImageRegionType &destRegion, const OutputImageRegionType &srcRegion)
Definition: otbDecimateImageFilter.hxx:64
otbDecimateImageFilter.h
otb::SubsampledImageRegionConstIterator::GoToBegin
void GoToBegin()
Definition: otbSubsampledImageRegionConstIterator.hxx:132
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbMacro.h
otbGenericMsgDebugMacro
#define otbGenericMsgDebugMacro(x)
Definition: otbMacro.h:63
otb::DecimateImageFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbDecimateImageFilter.h:69
otb::DecimateImageFilter::InputImageRegionType
InputImageType::RegionType InputImageRegionType
Definition: otbDecimateImageFilter.h:66
otb::DecimateImageFilter::GenerateOutputInformation
virtual void GenerateOutputInformation()
Definition: otbDecimateImageFilter.hxx:44
otb::SubsampledImageRegionConstIterator::IsAtEnd
bool IsAtEnd(void) const
Definition: otbSubsampledImageRegionConstIterator.h:161
otb::SubsampledImageRegionConstIterator
Regular subsample iterator over an image.
Definition: otbSubsampledImageRegionConstIterator.h:44
otb::DecimateImageFilter::ThreadedGenerateData
virtual void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId)
Definition: otbDecimateImageFilter.hxx:106
otb::DecimateImageFilter::OutputPixelType
OutputImageType::PixelType OutputPixelType
Definition: otbDecimateImageFilter.h:70
otb::DecimateImageFilter::PrintSelf
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const
Definition: otbDecimateImageFilter.hxx:37
otb::DecimateImageFilter::CallCopyInputRegionToOutputRegion
virtual void CallCopyInputRegionToOutputRegion(OutputImageRegionType &destRegion, const InputImageRegionType &srcRegion)
Definition: otbDecimateImageFilter.hxx:85