OTB  9.0.0
Orfeo Toolbox
otbSimpleRcsPanSharpeningFusionImageFilter.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 #ifndef otbSimpleRcsPanSharpeningFusionImageFilter_h
23 #define otbSimpleRcsPanSharpeningFusionImageFilter_h
24 
26 #include "otbImage.h"
27 #include "otbFunctorImageFilter.h"
28 
29 #include "itkProgressAccumulator.h"
30 
31 
32 namespace otb
33 {
51 template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision = float>
52 class ITK_EXPORT SimpleRcsPanSharpeningFusionImageFilter : public itk::ImageToImageFilter<TXsImageType, TOutputImageType>
53 {
54 public:
55 
58  typedef itk::ImageToImageFilter<TXsImageType, TOutputImageType> Superclass;
59  typedef itk::SmartPointer<Self> Pointer;
60  typedef itk::SmartPointer<const Self> ConstPointer;
61 
64 
66  typedef typename itk::Array<TInternalPrecision> ArrayType;
67 
69  itkNewMacro(Self);
70 
72  itkTypeMacro(SimpleRcsPanSharpeningFusionImageFilter, itk::ImageToImageFilter);
73 
75  typedef typename InternalImageType::SizeType RadiusType;
76 
78  itkGetMacro(Radius, RadiusType);
79  itkSetMacro(Radius, RadiusType);
81 
83  itkSetMacro(Filter, ArrayType);
84  itkGetConstReferenceMacro(Filter, ArrayType);
86 
87  virtual void SetPanInput(const TPanImageType* image);
88  const TPanImageType* GetPanInput(void) const;
89 
90  virtual void SetXsInput(const TXsImageType* path);
91  const TXsImageType* GetXsInput(void) const;
92 
93 protected:
96 
99 
101  void GenerateData() override;
102 
104  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
105 
106 private:
107  SimpleRcsPanSharpeningFusionImageFilter(Self&); // intentionally not implemented
108  void operator=(const Self&); // intentionally not implemented
109 
118  {
119  public:
120  // Implement the fusion as a three arguments operator
121  void operator()(typename TOutputImageType::PixelType& output, const typename TXsImageType::PixelType& xsPixel, const TInternalPrecision& smoothPanchroPixel,
122  const typename TPanImageType::PixelType& sharpPanchroPixel) const
123  {
124  TInternalPrecision scale = 1.;
125 
126  if (std::abs(smoothPanchroPixel) > 1e-10)
127  {
128  scale = sharpPanchroPixel / smoothPanchroPixel;
129  }
130 
131  // Perform fusion for each band with appropriate casting
132  for (unsigned int i = 0; i < xsPixel.Size(); ++i)
133  {
134  output[i] = static_cast<typename TOutputImageType::InternalPixelType>(xsPixel[i] * scale);
135  }
136  }
137 
138  constexpr size_t OutputSize(const std::array<size_t, 3>& inputsNbBands) const
139  {
140  return inputsNbBands[0];
141  }
142  };
143 
144 
153  {
154  public:
155  // Implement the fusion as a three arguments operator
156  void operator()(typename TOutputImageType::PixelType& output, const typename TXsImageType::PixelType& xsPixel, const TInternalPrecision& smoothPanchroPixel,
157  const typename TPanImageType::PixelType& sharpPanchroPixel) const
158  {
159  // Check for no data Pan value
160  if (m_NoDataValuePanAvailable && sharpPanchroPixel == m_NoDataValuePan)
161  {
162  for (unsigned int i = 0; i < xsPixel.Size(); ++i)
163  {
164  output[i] = static_cast<typename TOutputImageType::InternalPixelType>(m_NoDataValuesXs[i]);
165  }
166  return;
167  }
168 
169  TInternalPrecision scale = 1.;
170 
171  if (std::abs(smoothPanchroPixel) > 1e-10)
172  {
173  scale = sharpPanchroPixel / smoothPanchroPixel;
174  }
175 
176  // Perform fusion for each band with appropriate casting
177  for (unsigned int i = 0; i < xsPixel.Size(); ++i)
178  {
179  output[i] = (m_NoDataValuesXsAvailable[i] && (xsPixel[i] == m_NoDataValuesXs[i]))
180  ? static_cast<typename TOutputImageType::InternalPixelType>(xsPixel[i])
181  : static_cast<typename TOutputImageType::InternalPixelType>(xsPixel[i] * scale);
182  }
183  }
184 
185  void SetNoDataValuePanAvailable(bool noDataAvailable)
186  {
187  m_NoDataValuePanAvailable = noDataAvailable;
188  }
189 
190  void SetNoDataValuePan(typename TPanImageType::PixelType noDataValue)
191  {
192  m_NoDataValuePan = noDataValue;
193  }
194 
195  void SetNoDataValuesXsAvailable(std::vector<bool>& noDataValuesAvailable)
196  {
197  m_NoDataValuesXsAvailable = noDataValuesAvailable;
198  }
199 
200  void SetNoDataValuesXs(std::vector<typename TXsImageType::InternalPixelType>& noDataValues)
201  {
202  m_NoDataValuesXs = noDataValues;
203  }
204 
205  constexpr size_t OutputSize(const std::array<size_t, 3> inputsNbBands) const
206  {
207  return inputsNbBands[0];
208  }
209 
210  NoDataFusionFunctor() : m_NoDataValuePanAvailable(false), m_NoDataValuePan(0), m_NoDataValuesXsAvailable(false), m_NoDataValuesXs()
211  {
212  }
213 
214  private:
217  typename TPanImageType::InternalPixelType m_NoDataValuePan;
218 
220  std::vector<bool> m_NoDataValuesXsAvailable;
221  std::vector<typename TXsImageType::InternalPixelType> m_NoDataValuesXs;
222  };
223 
224 
230 
236 
240 
243 
246 
249 
252 
255 
258 
260  typename itk::ProgressAccumulator::Pointer m_ProgressAccumulator;
261 };
262 
263 } // end namespace otb
264 
265 #ifndef OTB_MANUAL_INSTANTIATION
267 #endif
268 
269 #endif
otb::SimpleRcsPanSharpeningFusionImageFilter::m_Radius
RadiusType m_Radius
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:254
otbFunctorImageFilter.h
otb::ConvolutionImageFilter
Applies a convolution filter to a mono channel image.
Definition: otbConvolutionImageFilter.h:68
otb::SimpleRcsPanSharpeningFusionImageFilter::NoDataFusionFunctor::SetNoDataValuesXs
void SetNoDataValuesXs(std::vector< typename TXsImageType::InternalPixelType > &noDataValues)
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:200
otb::SimpleRcsPanSharpeningFusionImageFilter::NoDataFusionFunctor
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:152
otb::SimpleRcsPanSharpeningFusionImageFilter::ConvolutionFilterType
otb::ConvolutionImageFilter< TPanImageType, InternalImageType, itk::ZeroFluxNeumannBoundaryCondition< TPanImageType >, TInternalPrecision > ConvolutionFilterType
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:239
otb::SimpleRcsPanSharpeningFusionImageFilter::NoDataFusionFunctor::NoDataFusionFunctor
NoDataFusionFunctor()
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:210
otb::SimpleRcsPanSharpeningFusionImageFilter::ArrayType
itk::Array< TInternalPrecision > ArrayType
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:66
otb::SimpleRcsPanSharpeningFusionImageFilter::m_UseNoData
bool m_UseNoData
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:251
otbImage.h
otb::SimpleRcsPanSharpeningFusionImageFilter::NoDataFusionFunctor::operator()
void operator()(typename TOutputImageType::PixelType &output, const typename TXsImageType::PixelType &xsPixel, const TInternalPrecision &smoothPanchroPixel, const typename TPanImageType::PixelType &sharpPanchroPixel) const
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:156
otb::SimpleRcsPanSharpeningFusionImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:60
otb::SimpleRcsPanSharpeningFusionImageFilter::NoDataFusionFilterType
FunctorImageFilter< NoDataFusionFunctor > NoDataFusionFilterType
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:235
otb::SimpleRcsPanSharpeningFusionImageFilter::InternalImageType
otb::Image< TInternalPrecision, TPanImageType::ImageDimension > InternalImageType
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:63
otb::FunctorImageFilter
A generic functor filter templated by its functor.
Definition: otbFunctorImageFilter.h:322
otb::SimpleRcsPanSharpeningFusionImageFilter::FusionFunctor::OutputSize
constexpr vcl_size_t OutputSize(const std::array< vcl_size_t, 3 > &inputsNbBands) const
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:138
otb::SimpleRcsPanSharpeningFusionImageFilter::FusionFunctor::operator()
void operator()(typename TOutputImageType::PixelType &output, const typename TXsImageType::PixelType &xsPixel, const TInternalPrecision &smoothPanchroPixel, const typename TPanImageType::PixelType &sharpPanchroPixel) const
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:121
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Image
Creation of an "otb" image which contains metadata.
Definition: otbImage.h:89
otb::ConvolutionImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbConvolutionImageFilter.h:83
otb::FunctorImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbFunctorImageFilter.h:329
otb::SimpleRcsPanSharpeningFusionImageFilter::NoDataFusionFunctor::m_NoDataValuePanAvailable
bool m_NoDataValuePanAvailable
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:216
otb::SimpleRcsPanSharpeningFusionImageFilter::NoDataFusionFunctor::SetNoDataValuesXsAvailable
void SetNoDataValuesXsAvailable(std::vector< bool > &noDataValuesAvailable)
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:195
otb::SimpleRcsPanSharpeningFusionImageFilter::FusionFilterType
FunctorImageFilter< FusionFunctor > FusionFilterType
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:229
otb::SimpleRcsPanSharpeningFusionImageFilter::NoDataFusionFunctor::m_NoDataValuePan
TPanImageType::InternalPixelType m_NoDataValuePan
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:217
otb::SimpleRcsPanSharpeningFusionImageFilter::m_ConvolutionFilter
ConvolutionFilterType::Pointer m_ConvolutionFilter
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:242
otb::SimpleRcsPanSharpeningFusionImageFilter::NoDataFusionFunctor::OutputSize
constexpr vcl_size_t OutputSize(const std::array< vcl_size_t, 3 > inputsNbBands) const
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:205
otb::SimpleRcsPanSharpeningFusionImageFilter::m_ProgressAccumulator
itk::ProgressAccumulator::Pointer m_ProgressAccumulator
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:260
otb::SimpleRcsPanSharpeningFusionImageFilter::RadiusType
InternalImageType::SizeType RadiusType
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:72
otb::Wrapper::Tags::Filter
static const std::string Filter
Definition: otbWrapperTags.h:39
otbSimpleRcsPanSharpeningFusionImageFilter.hxx
otbConvolutionImageFilter.h
otb::SimpleRcsPanSharpeningFusionImageFilter::m_Filter
ArrayType m_Filter
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:257
otb::SimpleRcsPanSharpeningFusionImageFilter::Self
SimpleRcsPanSharpeningFusionImageFilter Self
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:57
otb::SimpleRcsPanSharpeningFusionImageFilter
This class performs a simple Pan sharpening operation.
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:52
otb::SimpleRcsPanSharpeningFusionImageFilter::NoDataFusionFunctor::m_NoDataValuesXsAvailable
std::vector< bool > m_NoDataValuesXsAvailable
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:220
otb::SimpleRcsPanSharpeningFusionImageFilter::Superclass
itk::ImageToImageFilter< TXsImageType, TOutputImageType > Superclass
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:58
otb::SimpleRcsPanSharpeningFusionImageFilter::NoDataFusionFunctor::SetNoDataValuePanAvailable
void SetNoDataValuePanAvailable(bool noDataAvailable)
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:185
otb::SimpleRcsPanSharpeningFusionImageFilter::~SimpleRcsPanSharpeningFusionImageFilter
~SimpleRcsPanSharpeningFusionImageFilter() override
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:98
otb::SimpleRcsPanSharpeningFusionImageFilter::m_NoDataFusionFilter
NoDataFusionFilterType::Pointer m_NoDataFusionFilter
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:248
otb::SimpleRcsPanSharpeningFusionImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:59
otb::SimpleRcsPanSharpeningFusionImageFilter::NoDataFusionFunctor::m_NoDataValuesXs
std::vector< typename TXsImageType::InternalPixelType > m_NoDataValuesXs
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:221
otb::SimpleRcsPanSharpeningFusionImageFilter::FusionFunctor
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:117
otb::SimpleRcsPanSharpeningFusionImageFilter::m_FusionFilter
FusionFilterType::Pointer m_FusionFilter
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:245
otb::SimpleRcsPanSharpeningFusionImageFilter::NoDataFusionFunctor::SetNoDataValuePan
void SetNoDataValuePan(typename TPanImageType::PixelType noDataValue)
Definition: otbSimpleRcsPanSharpeningFusionImageFilter.h:190
otb::Image::SizeType
Superclass::SizeType SizeType
Definition: otbImage.h:148