OTB  10.0.0
Orfeo Toolbox
otbClampImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 
22 #ifndef otbClampImageFilter_hxx
23 #define otbClampImageFilter_hxx
24 
25 #include "otbClampImageFilter.h"
26 #include "itkImageScanlineIterator.h"
27 #include "itkImageScanlineConstIterator.h"
28 #include "itkImageRegionIterator.h"
29 #include "itkNumericTraits.h"
30 #include "itkObjectFactory.h"
31 #include "itkProgressReporter.h"
32 #include <limits>
33 
34 namespace otb
35 {
36 
40 template <class TInputImage, class TOutputImage>
42  :
43  m_Lower(std::numeric_limits<OutputPixelValueType>::lowest()),
44  m_Upper(std::numeric_limits<OutputPixelValueType>::max())
45 {
46  this->DynamicMultiThreadingOn();
47 }
48 
49 template <class TInputImage, class TOutputImage>
51 {
52  assert( lowerVal <= upperVal );
53  if ((m_Lower != lowerVal) || (m_Upper != upperVal))
54  {
55  m_Lower = lowerVal;
56  m_Upper = upperVal;
57  this->GetFunctor().SetThresholds(m_Lower, m_Upper);
58  this->Modified();
59  }
60 }
61 
65 template <class TInputImage, class TOutputImage>
66 void ClampImageFilter<TInputImage, TOutputImage>::PrintSelf(std::ostream& os, itk::Indent indent) const
67 {
68  Superclass::PrintSelf(os, indent);
69 
70  os << indent << "Lower: " << static_cast<typename itk::NumericTraits<OutputImagePixelType>::PrintType>(m_Lower) << std::endl;
71  os << indent << "Upper: " << static_cast<typename itk::NumericTraits<OutputImagePixelType>::PrintType>(m_Upper) << std::endl;
72 }
73 
77 template <class TInputImage, class TOutputImage>
79 {
80  if (m_Upper != thresh || m_Lower > std::numeric_limits<OutputPixelValueType>::lowest())
81  {
82  m_Lower = std::numeric_limits<OutputPixelValueType>::lowest();
83  m_Upper = thresh;
84  this->GetFunctor().SetThresholds(m_Lower, m_Upper);
85  this->Modified();
86  }
87 }
89 
93 template <class TInputImage, class TOutputImage>
95 {
96  if (m_Lower != thresh || m_Upper < std::numeric_limits<OutputPixelValueType>::max())
97  {
98  m_Upper = std::numeric_limits<OutputPixelValueType>::max();
99  m_Lower = thresh;
100  this->GetFunctor().SetThresholds(m_Lower, m_Upper);
101  this->Modified();
102  }
103 }
105 
106 
110 template <class TInputImage, class TOutputImage>
112 {
113  if (lower > upper)
114  {
115  itkExceptionMacro(<< "Lower threshold cannot be greater than upper threshold.");
116  return;
117  }
119 
120  if (m_Lower != lower || m_Upper != upper)
121  {
122  m_Lower = lower;
123  m_Upper = upper;
124  this->GetFunctor().SetThresholds(m_Lower, m_Upper);
125  this->Modified();
126  }
127 }
128 
129 template <class TInputImage, class TOutputImage>
130 void
133 {
134  const auto& regionSize = outputRegionForThread.GetSize();
135 
136  if (regionSize[0] == 0)
137  {
138  return;
139  }
140 
141  // Build output iterator
142  itk::ImageScanlineConstIterator<InputImageType> inIt(this->GetInput(), outputRegionForThread);
143  itk::ImageScanlineIterator<OutputImageType> outIt(this->GetOutput(), outputRegionForThread);
144 
145  // Build a default value
146  typename OutputImageType::PixelType outputValueHolder;
147  // Luc: I'm not sure this will be the correct size given the convoluted
148  // size computations done in the ConvertTypeFunctor
149  itk::NumericTraits<typename OutputImageType::PixelType>::SetLength(outputValueHolder, this->GetOutput()->GetNumberOfComponentsPerPixel());
150 
151  while (!outIt.IsAtEnd())
152  {
153  // MoveIterartors will ++ all iterators in the tuple
154  for (; !outIt.IsAtEndOfLine(); ++outIt, ++inIt)
155  {
156  // This will call the operator with inputIterators Get() results
157  // and fill outputValueHolder with the result.
158  m_Functor(outputValueHolder, inIt.Get());
159  outIt.Set(outputValueHolder);
160  }
161  outIt.NextLine();
162  inIt.NextLine();
163  }
164 }
165 
166 } // end namespace otb
167 
168 #endif
void SetThresholds(OutputPixelValueType lowerVal, OutputPixelValueType upperVal)
void ClampOutside(const OutputPixelValueType &lower, const OutputPixelValueType &upper)
typename OutputImageType::RegionType OutputImageRegionType
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
typename itk::NumericTraits< OutputInternalPixelType >::ValueType OutputPixelValueType
void ClampAbove(const OutputPixelValueType &thresh)
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void ClampBelow(const OutputPixelValueType &thresh)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.