OTB  10.0.0
Orfeo Toolbox
otbPrintableImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
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 otbPrintableImageFilter_h
24 #define otbPrintableImageFilter_h
25 
26 #include "otbImage.h"
27 #include "itkImageToImageFilter.h"
30 #include "itkBinaryFunctorImageFilter.h"
31 
32 namespace otb
33 {
34 namespace Functor
35 {
44 template <class TInputPixel, class TMaskPixel, class TOutputPixel>
45 class ITK_EXPORT MaskFunctor
46 {
47 public:
49  {
50  m_BackgroundValue = 0;
51  m_ObjectColor.SetSize(3);
52  m_ObjectColor.Fill(255);
53  };
55  {
56  }
57 
58  typedef TInputPixel InputPixelType;
59  typedef TMaskPixel MaskPixelType;
60  typedef TOutputPixel OutputPixelType;
61  typedef typename OutputPixelType::ValueType OutputInternalPixelType;
62 
64  {
65  return m_BackgroundValue;
66  }
68  {
69  m_BackgroundValue = val;
70  }
71 
73  {
74  return m_ObjectColor;
75  }
77  {
78  m_ObjectColor = val;
79  }
80 
82  {
83  OutputPixelType outPix;
84  if (maskPix == m_BackgroundValue)
85  {
86  outPix.SetSize(inPix.Size());
87  for (unsigned int i = 0; i < outPix.Size(); ++i)
88  {
89  outPix[i] = static_cast<OutputInternalPixelType>(inPix[i]);
90  }
91  }
92  else
93  {
94  outPix = m_ObjectColor;
95  }
96 
97  return outPix;
98  }
99 
100 protected:
103 };
104 }
105 
123 template <class TInputImage, class TMaskImage = otb::Image<unsigned char, 2>>
124 class ITK_EXPORT PrintableImageFilter : public itk::ImageToImageFilter<TInputImage, otb::VectorImage<unsigned char, 2>>
125 {
126 public:
129  typedef itk::SmartPointer<Self> Pointer;
130  typedef itk::SmartPointer<const Self> ConstPointer;
131 
132  typedef TInputImage InputImageType;
133  typedef typename InputImageType::PixelType InputPixelType;
134  typedef typename InputImageType::InternalPixelType InputInternalPixelType;
135  // typedef typename itk::NumericTraits<InputPixelType>::ValueType InputInternalPixelType;
136  typedef unsigned char OutputInternalPixelType;
139 
140  typedef TMaskImage MaskImageType;
141  typedef typename MaskImageType::Pointer MaskImagePointerType;
142  typedef typename MaskImageType::PixelType MaskPixelType;
143 
146 
148 
150  typedef itk::BinaryFunctorImageFilter<OutputImageType, MaskImageType, OutputImageType, FunctorType> FunctorFilterType;
151  typedef typename FunctorFilterType::Pointer FunctorFilterPointerType;
152 
154  itkNewMacro(Self);
155 
157  itkTypeMacro(PrintableImageFilter, itk::ImageToImageFilter);
158 
160  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
161 
162  void SetChannel(unsigned int channel);
163  const ChannelsType GetChannels(void) const;
164 
165  otbSetObjectMemberMacro(Rescaler, AutomaticInputMinMaxComputation, bool);
166  otbGetObjectMemberMacro(Rescaler, AutomaticInputMinMaxComputation, bool);
167  otbSetObjectMemberMacro(Rescaler, InputMinimum, InputPixelType);
168  otbGetObjectMemberMacro(Rescaler, InputMinimum, InputPixelType);
169  otbSetObjectMemberMacro(Rescaler, InputMaximum, InputPixelType);
170  otbGetObjectMemberMacro(Rescaler, InputMaximum, InputPixelType);
171 
176  void SetInputMask(const MaskImageType* mask);
177 
182  MaskImageType* GetInputMask(void);
183 
184  itkSetMacro(UseMask, bool);
185  itkGetMacro(UseMask, bool);
186 
188  {
189  return m_ChannelList;
190  }
191  /* Set the selected channel index (order is important) */
193  {
194  if (chList.size() != 3)
195  {
196  itkExceptionMacro(<< "Invalid channel list, size is " << chList.size() << " instead of 3");
197  }
198  m_ChannelList = chList;
199  this->Modified();
200  }
201 
204  {
205  if (val.GetSize() != 3)
206  {
207  itkExceptionMacro(<< "Invalid object color, size is " << val.Size() << " instead of 3");
208  }
209  m_ObjectColor = val;
210  m_MaskFilter->GetFunctor().SetObjectColor(val);
211  this->Modified();
212  }
213  itkGetMacro(ObjectColor, OutputPixelType);
215 
217  {
218  m_BackgroundMaskValue = val;
219  m_MaskFilter->GetFunctor().SetBackgroundValue(val);
220  this->Modified();
221  }
222  itkGetMacro(BackgroundMaskValue, MaskPixelType);
223 
232  void GenerateOutputInformation() override;
233 
234 protected:
236 
237  void BeforeGenerateData();
238  void GenerateData() override;
239 
240 private:
241  PrintableImageFilter(Self&); // intentionally not implemented
242  void operator=(const Self&); // intentionally not implemented
243 
246  // Foreground mask value
248  // Objects (of the mask) will be displayer with the chosen color.
250  // Use mask
251  bool m_UseMask;
252  // Used channel for output Image
254  // Foreground mask value
255  // MaskPixelType m_ForegroundMaskValue;
256  // Background mask value
258 };
259 
260 } // end namespace otb
261 
262 #ifndef OTB_MANUAL_INSTANTIATION
264 #endif
265 
266 #endif
Output is a InputPixel if MaskPixel is m_Background and a defined other value (m_ObjectColor) otherwi...
OutputPixelType::ValueType OutputInternalPixelType
void SetBackgroundValue(MaskPixelType val)
OutputPixelType operator()(InputPixelType inPix, MaskPixelType maskPix) const
void SetObjectColor(OutputPixelType val)
Extract a spatial or spectral subset of a multi-channel image.
std::vector< unsigned int > ChannelsType
itk::SmartPointer< Self > Pointer
This class is a helper class to turn a vector image to a generic 8 bytes RGB image....
otbGetObjectMemberMacro(Rescaler, InputMinimum, InputPixelType)
VectorRescalerType::Pointer m_Rescaler
VectorImage< OutputInternalPixelType, 2 > OutputImageType
FunctorFilterType::Pointer FunctorFilterPointerType
itk::SmartPointer< Self > Pointer
otbGetObjectMemberMacro(Rescaler, AutomaticInputMinMaxComputation, bool)
FunctorFilterPointerType m_MaskFilter
InputImageType::PixelType InputPixelType
otb::MultiChannelExtractROI< InputInternalPixelType, InputInternalPixelType > ChannelExtractorType
void SetBackgroundMaskValue(MaskPixelType val)
ChannelExtractorType::Pointer m_Extractor
void SetChannelList(ChannelsType chList)
otbSetObjectMemberMacro(Rescaler, InputMaximum, InputPixelType)
otbSetObjectMemberMacro(Rescaler, InputMinimum, InputPixelType)
itk::SmartPointer< const Self > ConstPointer
otbSetObjectMemberMacro(Rescaler, AutomaticInputMinMaxComputation, bool)
otbGetObjectMemberMacro(Rescaler, InputMaximum, InputPixelType)
ChannelsType const GetChannelList()
OutputImageType::PixelType OutputPixelType
MaskImageType::PixelType MaskPixelType
VectorRescaleIntensityImageFilter< typename ChannelExtractorType::OutputImageType, OutputImageType > VectorRescalerType
ChannelExtractorType::ChannelsType ChannelsType
MaskImageType::Pointer MaskImagePointerType
itk::BinaryFunctorImageFilter< OutputImageType, MaskImageType, OutputImageType, FunctorType > FunctorFilterType
void SetObjectColor(OutputPixelType val)
Functor::MaskFunctor< InputPixelType, MaskPixelType, OutputPixelType > FunctorType
itk::ImageToImageFilter< TInputImage, otb::VectorImage< unsigned char, 2 > > Superclass
void operator=(const Self &)
InputImageType::InternalPixelType InputInternalPixelType
Creation of an "otb" vector image which contains metadata.
Superclass::PixelType PixelType
This filter performs a rescaling of a vector image on a per band basis.
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
template class OTBImageBase_EXPORT_TEMPLATE VectorImage< unsigned char, 2 >