OTB  9.0.0
Orfeo Toolbox
otbChangeLabelImageFilter.h
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 #ifndef otbChangeLabelImageFilter_h
22 #define otbChangeLabelImageFilter_h
23 
24 #include "itkUnaryFunctorImageFilter.h"
25 #include "itkConceptChecking.h"
26 #include "itkSimpleDataObjectDecorator.h"
27 
28 #include <map>
29 
30 namespace otb
31 {
32 
43 namespace Functor
44 {
45 
46 template <class TInput, class TOutput>
48 {
49 public:
50  typedef typename TOutput::ValueType ValueType;
51 
53  {
54  }
56  {
57  }
58 
59  typedef std::map<TInput, TOutput> ChangeMapType;
60 
61  void SetNumberOfComponentsPerPixel(unsigned int nb)
62  {
64  }
66  {
68  }
69  bool operator!=(const VectorChangeLabel& other) const
70  {
71  if (m_ChangeMap != other.m_ChangeMap)
72  {
73  return true;
74  }
75  return false;
76  }
77  bool operator==(const VectorChangeLabel& other) const
78  {
79  return !(*this != other);
80  }
81  TOutput GetChange(const TInput& original)
82  {
83  return m_ChangeMap[original];
84  }
85 
86  void SetChange(const TInput& original, const TOutput& result)
87  {
88  m_ChangeMap[original] = result;
89  }
90 
91  void SetChangeMap(const ChangeMapType& changeMap)
92  {
93  m_ChangeMap = changeMap;
94  }
95 
97  {
98  m_ChangeMap.clear();
99  }
100 
101  inline TOutput operator()(const TInput& A)
102  {
103  TOutput out;
104  out.SetSize(m_NumberOfComponentsPerPixel);
105 
106  if (m_ChangeMap.find(A) != m_ChangeMap.end())
107  {
108  out = m_ChangeMap[A];
109  }
110  else
111  {
112  out.Fill(static_cast<ValueType>(A));
113  }
114  return out;
115  }
116 
117 private:
120 };
121 }
122 
123 template <class TInputImage, class TOutputImage>
124 class ITK_EXPORT ChangeLabelImageFilter
125  : public itk::UnaryFunctorImageFilter<TInputImage, TOutputImage,
126  Functor::VectorChangeLabel<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
127 {
128 public:
131  typedef itk::UnaryFunctorImageFilter<TInputImage, TOutputImage, Functor::VectorChangeLabel<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
133  typedef itk::SmartPointer<Self> Pointer;
134  typedef itk::SmartPointer<const Self> ConstPointer;
135 
137  itkNewMacro(Self);
138 
140  itkTypeMacro(ChangeLabelImageFilter, itk::UnaryFunctorImageFilter);
141 
143  typedef typename TInputImage::PixelType InputPixelType;
144  typedef typename TOutputImage::PixelType OutputPixelType;
145 
147  typedef std::map<InputPixelType, OutputPixelType> ChangeMapType;
148 
150  void SetChange(const InputPixelType& original, const OutputPixelType& result);
151 
153  void SetChangeMap(const ChangeMapType& changeMap);
154 
156  void ClearChangeMap();
157 
159  void SetNumberOfComponentsPerPixel(unsigned int nb)
160  {
161  m_NumberOfComponentsPerPixel = nb;
162  this->GetFunctor().SetNumberOfComponentsPerPixel(m_NumberOfComponentsPerPixel);
163  this->Modified();
164  }
165  itkGetMacro(NumberOfComponentsPerPixel, unsigned int);
167 
168 protected:
171  {
172  }
174  void GenerateOutputInformation() override;
175 
176  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
177 
178 private:
179  ChangeLabelImageFilter(const Self&) = delete;
180  void operator=(const Self&) = delete;
181 
184 };
185 
186 } // end namespace otb
187 
188 #ifndef OTB_MANUAL_INSTANTIATION
190 #endif
191 
192 #endif
otb::ChangeLabelImageFilter::~ChangeLabelImageFilter
~ChangeLabelImageFilter() override
Number of components per pixel.
Definition: otbChangeLabelImageFilter.h:170
otb::ChangeLabelImageFilter::Self
ChangeLabelImageFilter Self
Definition: otbChangeLabelImageFilter.h:130
otb::ChangeLabelImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbChangeLabelImageFilter.h:134
otb::ChangeLabelImageFilter::SetNumberOfComponentsPerPixel
void SetNumberOfComponentsPerPixel(unsigned int nb)
Definition: otbChangeLabelImageFilter.h:159
otb::Functor::VectorChangeLabel::ChangeMapType
std::map< TInput, TOutput > ChangeMapType
Definition: otbChangeLabelImageFilter.h:59
otbChangeLabelImageFilter.hxx
otb::Functor::VectorChangeLabel::m_ChangeMap
ChangeMapType m_ChangeMap
Definition: otbChangeLabelImageFilter.h:118
otb::Functor::VectorChangeLabel
Definition: otbChangeLabelImageFilter.h:47
otb::ChangeLabelImageFilter::m_NumberOfComponentsPerPixel
unsigned int m_NumberOfComponentsPerPixel
Number of components per pixel.
Definition: otbChangeLabelImageFilter.h:183
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::VectorChangeLabel::SetChange
void SetChange(const TInput &original, const TOutput &result)
Definition: otbChangeLabelImageFilter.h:86
otb::ChangeLabelImageFilter::InputPixelType
TInputImage::PixelType InputPixelType
Definition: otbChangeLabelImageFilter.h:140
otb::Functor::VectorChangeLabel::~VectorChangeLabel
virtual ~VectorChangeLabel()
Definition: otbChangeLabelImageFilter.h:55
otb::Functor::VectorChangeLabel::SetChangeMap
void SetChangeMap(const ChangeMapType &changeMap)
Definition: otbChangeLabelImageFilter.h:91
otb::ChangeLabelImageFilter::OutputPixelType
TOutputImage::PixelType OutputPixelType
Definition: otbChangeLabelImageFilter.h:144
otb::Functor::VectorChangeLabel::operator==
bool operator==(const VectorChangeLabel &other) const
Definition: otbChangeLabelImageFilter.h:77
otb::Functor::VectorChangeLabel::m_NumberOfComponentsPerPixel
unsigned int m_NumberOfComponentsPerPixel
Definition: otbChangeLabelImageFilter.h:119
otb::ChangeLabelImageFilter::Superclass
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::VectorChangeLabel< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
Definition: otbChangeLabelImageFilter.h:132
otb::Functor::VectorChangeLabel::GetNumberOfComponentsPerPixel
unsigned int GetNumberOfComponentsPerPixel()
Definition: otbChangeLabelImageFilter.h:65
otb::Functor::VectorChangeLabel::GetChange
TOutput GetChange(const TInput &original)
Definition: otbChangeLabelImageFilter.h:81
otb::ChangeLabelImageFilter::ChangeMapType
std::map< InputPixelType, OutputPixelType > ChangeMapType
Definition: otbChangeLabelImageFilter.h:147
otb::Functor::VectorChangeLabel::VectorChangeLabel
VectorChangeLabel()
Definition: otbChangeLabelImageFilter.h:52
otb::Functor::VectorChangeLabel::ValueType
TOutput::ValueType ValueType
Definition: otbChangeLabelImageFilter.h:50
otb::ChangeLabelImageFilter
Change Sets of Labels.
Definition: otbChangeLabelImageFilter.h:124
otb::Functor::VectorChangeLabel::operator!=
bool operator!=(const VectorChangeLabel &other) const
Definition: otbChangeLabelImageFilter.h:69
otb::Functor::VectorChangeLabel::operator()
TOutput operator()(const TInput &A)
Definition: otbChangeLabelImageFilter.h:101
otb::ChangeLabelImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbChangeLabelImageFilter.h:133
otb::Functor::VectorChangeLabel::SetNumberOfComponentsPerPixel
void SetNumberOfComponentsPerPixel(unsigned int nb)
Definition: otbChangeLabelImageFilter.h:61
otb::Functor::VectorChangeLabel::ClearChangeMap
void ClearChangeMap()
Definition: otbChangeLabelImageFilter.h:96