OTB  9.0.0
Orfeo Toolbox
otbThresholdVectorImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 otbThresholdVectorImageFilter_hxx
23 #define otbThresholdVectorImageFilter_hxx
24 
26 #include "itkImageRegionIterator.h"
27 #include "itkNumericTraits.h"
28 #include "itkObjectFactory.h"
29 #include "itkProgressReporter.h"
30 
31 namespace otb
32 {
33 
37 template <class TInputImage, class TOutputImage>
39  :
40  m_OutsideValue(itk::NumericTraits<OutputImageInternalPixelType>::Zero),
41  m_Lower(itk::NumericTraits<InputImageInternalPixelType>::NonpositiveMin()),
42  m_Upper(itk::NumericTraits<InputImageInternalPixelType>::max())
43 {}
44 
45 
49 template <class TInputImage, class TOutputImage>
50 void ThresholdVectorImageFilter<TInputImage, TOutputImage>::PrintSelf(std::ostream& os, itk::Indent indent) const
51 {
52  Superclass::PrintSelf(os, indent);
53 
54  os << indent << "OutsideValue: " << static_cast<typename itk::NumericTraits<InputImageInternalPixelType>::PrintType>(m_OutsideValue) << std::endl;
55  os << indent << "Lower: " << static_cast<typename itk::NumericTraits<InputImageInternalPixelType>::PrintType>(m_Lower) << std::endl;
56  os << indent << "Upper: " << static_cast<typename itk::NumericTraits<InputImageInternalPixelType>::PrintType>(m_Upper) << std::endl;
57 }
58 
62 template <class TInputImage, class TOutputImage>
64 {
65  if (m_Upper != thresh || m_Lower > itk::NumericTraits<InputImageInternalPixelType>::NonpositiveMin())
66  {
67  m_Lower = itk::NumericTraits<InputImageInternalPixelType>::NonpositiveMin();
68  m_Upper = thresh;
69  this->Modified();
70  }
71 }
73 
77 template <class TInputImage, class TOutputImage>
79 {
80  if (m_Lower != thresh || m_Upper < itk::NumericTraits<InputImageInternalPixelType>::max())
81  {
82  m_Lower = thresh;
83  m_Upper = itk::NumericTraits<InputImageInternalPixelType>::max();
84  this->Modified();
85  }
86 }
88 
89 
93 template <class TInputImage, class TOutputImage>
95 {
96  if (lower > upper)
97  {
98  itkExceptionMacro(<< "Lower threshold cannot be greater than upper threshold.");
99  return;
100  }
102 
103  if (m_Lower != lower || m_Upper != upper)
104  {
105  m_Lower = lower;
106  m_Upper = upper;
107  this->Modified();
108  }
109 }
110 
111 
115 template <class TInputImage, class TOutputImage>
117 {
118  itkDebugMacro(<< "Actually executing");
119 
120  // Get the input and output pointers
121  InputImagePointer inputPtr = this->GetInput();
122  OutputImagePointer outputPtr = this->GetOutput(0);
123 
124  // Define/declare an iterator that will walk the output region for this
125  // thread.
126  typedef itk::ImageRegionConstIterator<TInputImage> InputIterator;
127  typedef itk::ImageRegionIterator<TOutputImage> OutputIterator;
128 
129  InputIterator inIt(inputPtr, outputRegionForThread);
130  OutputIterator outIt(outputPtr, outputRegionForThread);
131 
132  // support progress methods/callbacks
133  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
134 
135  // walk the regions, threshold each pixel
136  while (!outIt.IsAtEnd() && !inIt.IsAtEnd())
137  {
138  const InputImagePixelType inPix = inIt.Get();
139  unsigned int l_size = inPix.Size();
140  OutputImagePixelType outPix;
141  outPix.SetSize(l_size);
142  for (unsigned int i = 0; i < l_size; i++)
143  {
144  const InputImageInternalPixelType value = inPix[i];
145 
146  if (m_Lower <= value && value <= m_Upper)
147  {
148  // pixel passes to output unchanged and is replaced by m_OutsideValue in
149  // the inverse output image
150  outPix[i] = static_cast<OutputImageInternalPixelType>(value);
151  }
152  else
153  {
154  outPix[i] = static_cast<OutputImageInternalPixelType>(m_OutsideValue);
155  }
156  }
157 
158  outIt.Set(outPix);
159 
160  ++inIt;
161  ++outIt;
162  progress.CompletedPixel();
163  }
164 }
165 
166 } // end namespace itk
167 
168 #endif
otb::ThresholdVectorImageFilter::OutputImagePixelType
OutputImageType::PixelType OutputImagePixelType
Definition: otbThresholdVectorImageFilter.h:71
otb::ThresholdVectorImageFilter::OutputImagePointer
OutputImageType::Pointer OutputImagePointer
Definition: otbThresholdVectorImageFilter.h:69
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ThresholdVectorImageFilter::ThresholdBelow
void ThresholdBelow(const InputImageInternalPixelType &thresh)
Definition: otbThresholdVectorImageFilter.hxx:78
otb::ThresholdVectorImageFilter::InputImageInternalPixelType
InputImageType::InternalPixelType InputImageInternalPixelType
Definition: otbThresholdVectorImageFilter.h:65
otb::ThresholdVectorImageFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbThresholdVectorImageFilter.h:70
otbThresholdVectorImageFilter.h
otb::ThresholdVectorImageFilter::ThresholdVectorImageFilter
ThresholdVectorImageFilter()
Definition: otbThresholdVectorImageFilter.hxx:38
otb::ThresholdVectorImageFilter::OutputImageInternalPixelType
OutputImageType::InternalPixelType OutputImageInternalPixelType
Definition: otbThresholdVectorImageFilter.h:72
otb::ThresholdVectorImageFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbThresholdVectorImageFilter.hxx:50
otb::ThresholdVectorImageFilter::ThreadedGenerateData
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType ThrethreadId) override
Definition: otbThresholdVectorImageFilter.hxx:116
itk
Definition: otbNoDataHelper.h:31
otb::ThresholdVectorImageFilter::ThresholdOutside
void ThresholdOutside(const InputImageInternalPixelType &lower, const InputImageInternalPixelType &upper)
Definition: otbThresholdVectorImageFilter.hxx:94
otb::ThresholdVectorImageFilter::ThresholdAbove
void ThresholdAbove(const InputImageInternalPixelType &thresh)
Definition: otbThresholdVectorImageFilter.hxx:63
otb::ThresholdVectorImageFilter::InputImagePointer
InputImageType::ConstPointer InputImagePointer
Definition: otbThresholdVectorImageFilter.h:62
otb::ThresholdVectorImageFilter::InputImagePixelType
InputImageType::PixelType InputImagePixelType
Definition: otbThresholdVectorImageFilter.h:64