OTB  9.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-2022 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
otb::PrintableImageFilter::m_MaskFilter
FunctorFilterPointerType m_MaskFilter
Definition: otbPrintableImageFilter.h:247
otb::PrintableImageFilter::OutputImageType
VectorImage< OutputInternalPixelType, 2 > OutputImageType
Definition: otbPrintableImageFilter.h:137
otb::PrintableImageFilter::MaskPixelType
MaskImageType::PixelType MaskPixelType
Definition: otbPrintableImageFilter.h:142
otb::Functor::MaskFunctor::~MaskFunctor
~MaskFunctor()
Definition: otbPrintableImageFilter.h:54
otb::PrintableImageFilter::GetChannelList
const ChannelsType GetChannelList()
Definition: otbPrintableImageFilter.h:187
otb::MultiChannelExtractROI::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbMultiChannelExtractROI.h:53
otb::Functor::MaskFunctor::operator()
OutputPixelType operator()(InputPixelType inPix, MaskPixelType maskPix) const
Definition: otbPrintableImageFilter.h:81
otb::PrintableImageFilter::SetObjectColor
void SetObjectColor(OutputPixelType val)
Definition: otbPrintableImageFilter.h:203
otbMultiChannelExtractROI.h
otb::VectorRescaleIntensityImageFilter
This filter performs a rescaling of a vector image on a per band basis.
Definition: otbVectorRescaleIntensityImageFilter.h:220
otbImage.h
otb::PrintableImageFilter::SetBackgroundMaskValue
void SetBackgroundMaskValue(MaskPixelType val)
Definition: otbPrintableImageFilter.h:216
otb::PrintableImageFilter::SetChannelList
void SetChannelList(ChannelsType chList)
Definition: otbPrintableImageFilter.h:192
otb::VectorImage< unsigned char, 2 >
template class OTBImageBase_EXPORT_TEMPLATE VectorImage< unsigned char, 2 >
otb::Functor::MaskFunctor::OutputInternalPixelType
OutputPixelType::ValueType OutputInternalPixelType
Definition: otbPrintableImageFilter.h:61
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::PrintableImageFilter::InputPixelType
InputImageType::PixelType InputPixelType
Definition: otbPrintableImageFilter.h:133
otb::PrintableImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbPrintableImageFilter.h:130
otb::PrintableImageFilter::Self
PrintableImageFilter Self
Definition: otbPrintableImageFilter.h:127
otb::MultiChannelExtractROI::ChannelsType
std::vector< unsigned int > ChannelsType
Definition: otbMultiChannelExtractROI.h:86
otb::PrintableImageFilter::m_ChannelList
ChannelsType m_ChannelList
Definition: otbPrintableImageFilter.h:253
otbPrintableImageFilter.hxx
otb::PrintableImageFilter::MaskImageType
TMaskImage MaskImageType
Definition: otbPrintableImageFilter.h:140
otb::PrintableImageFilter::ChannelExtractorType
otb::MultiChannelExtractROI< InputInternalPixelType, InputInternalPixelType > ChannelExtractorType
Definition: otbPrintableImageFilter.h:144
otb::Functor::MaskFunctor::SetBackgroundValue
void SetBackgroundValue(MaskPixelType val)
Definition: otbPrintableImageFilter.h:67
otb::Functor::MaskFunctor
Output is a InputPixel if MaskPixel is m_Background and a defined other value (m_ObjectColor) otherwi...
Definition: otbPrintableImageFilter.h:45
otb::Functor::MaskFunctor::SetObjectColor
void SetObjectColor(OutputPixelType val)
Definition: otbPrintableImageFilter.h:76
otb::PrintableImageFilter::m_BackgroundMaskValue
MaskPixelType m_BackgroundMaskValue
Definition: otbPrintableImageFilter.h:257
otb::PrintableImageFilter::MaskImagePointerType
MaskImageType::Pointer MaskImagePointerType
Definition: otbPrintableImageFilter.h:141
otb::MultiChannelExtractROI
Extract a spatial or spectral subset of a multi-channel image.
Definition: otbMultiChannelExtractROI.h:47
otb::PrintableImageFilter::m_ObjectColor
OutputPixelType m_ObjectColor
Definition: otbPrintableImageFilter.h:249
otb::Functor::MaskFunctor::m_ObjectColor
OutputPixelType m_ObjectColor
Definition: otbPrintableImageFilter.h:102
otb::PrintableImageFilter::m_Rescaler
VectorRescalerType::Pointer m_Rescaler
Definition: otbPrintableImageFilter.h:244
otb::Functor::MaskFunctor::GetObjectColor
OutputPixelType GetObjectColor()
Definition: otbPrintableImageFilter.h:72
otb::Functor::MaskFunctor::InputPixelType
TInputPixel InputPixelType
Definition: otbPrintableImageFilter.h:58
otb::PrintableImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbPrintableImageFilter.h:129
otb::PrintableImageFilter::VectorRescalerType
VectorRescaleIntensityImageFilter< typename ChannelExtractorType::OutputImageType, OutputImageType > VectorRescalerType
Definition: otbPrintableImageFilter.h:147
otb::PrintableImageFilter::InputInternalPixelType
InputImageType::InternalPixelType InputInternalPixelType
Definition: otbPrintableImageFilter.h:134
otbVectorRescaleIntensityImageFilter.h
otb::Functor::MaskFunctor::MaskPixelType
TMaskPixel MaskPixelType
Definition: otbPrintableImageFilter.h:59
otb::Functor::MaskFunctor::OutputPixelType
TOutputPixel OutputPixelType
Definition: otbPrintableImageFilter.h:60
otb::PrintableImageFilter::FunctorFilterPointerType
FunctorFilterType::Pointer FunctorFilterPointerType
Definition: otbPrintableImageFilter.h:151
otb::PrintableImageFilter::m_Extractor
ChannelExtractorType::Pointer m_Extractor
Definition: otbPrintableImageFilter.h:245
otb::Functor::MaskFunctor::MaskFunctor
MaskFunctor()
Definition: otbPrintableImageFilter.h:48
otb::VectorImage::PixelType
Superclass::PixelType PixelType
Definition: otbVectorImage.h:63
otb::PrintableImageFilter::ChannelsType
ChannelExtractorType::ChannelsType ChannelsType
Definition: otbPrintableImageFilter.h:145
otb::Functor::MaskFunctor::m_BackgroundValue
MaskPixelType m_BackgroundValue
Definition: otbPrintableImageFilter.h:101
otb::VectorRescaleIntensityImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbVectorRescaleIntensityImageFilter.h:230
otb::PrintableImageFilter::Superclass
itk::ImageToImageFilter< TInputImage, otb::VectorImage< unsigned char, 2 > > Superclass
Definition: otbPrintableImageFilter.h:128
otb::PrintableImageFilter::OutputPixelType
OutputImageType::PixelType OutputPixelType
Definition: otbPrintableImageFilter.h:138
otb::Functor::MaskFunctor::GetBackgroundValue
MaskPixelType GetBackgroundValue()
Definition: otbPrintableImageFilter.h:63
otb::PrintableImageFilter::InputImageType
TInputImage InputImageType
Definition: otbPrintableImageFilter.h:132
otbGetObjectMemberMacro
#define otbGetObjectMemberMacro(object, name, type)
Definition: otbMacro.h:89
otb::PrintableImageFilter::m_UseMask
bool m_UseMask
Definition: otbPrintableImageFilter.h:251
otb::PrintableImageFilter::OutputInternalPixelType
unsigned char OutputInternalPixelType
Definition: otbPrintableImageFilter.h:136
otbSetObjectMemberMacro
#define otbSetObjectMemberMacro(object, name, type)
Definition: otbMacro.h:79
otb::PrintableImageFilter::FunctorType
Functor::MaskFunctor< InputPixelType, MaskPixelType, OutputPixelType > FunctorType
Definition: otbPrintableImageFilter.h:149
otb::PrintableImageFilter::FunctorFilterType
itk::BinaryFunctorImageFilter< OutputImageType, MaskImageType, OutputImageType, FunctorType > FunctorFilterType
Definition: otbPrintableImageFilter.h:150
otb::PrintableImageFilter
This class is a helper class to turn a vector image to a generic 8 bytes RGB image....
Definition: otbPrintableImageFilter.h:124
otb::VectorImage
Creation of an "otb" vector image which contains metadata.
Definition: otbVectorImage.h:45