otbSimpleRcsPanSharpeningFusionImageFilter.h 5.94 KB
Newer Older
Emmanuel Christophe's avatar
Emmanuel Christophe committed
1
/*=========================================================================
2

Emmanuel Christophe's avatar
Emmanuel Christophe committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.

  Some parts of this code are derived from ITK. See ITKCopyright.txt
  for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __otbSimpleRcsPanSharpeningFusionImageFilter_h
#define __otbSimpleRcsPanSharpeningFusionImageFilter_h

24
#include "otbConvolutionImageFilter.h"
25
#include "otbImage.h"
26
#include "itkTernaryFunctorImageFilter.h"
27
28
29

#include "itkProgressAccumulator.h"

30

31
32
33
34
35
36
37
38
39
40
41
42
namespace otb
{
/**
 * \class SimpleRcsPanSharpeningFusionImageFilter
 * \brief This class performs a simple Pan sharpening operation
 *
 * Given a Pan image and the corresponding Xs image (oversampled to have the
 * same number of pixels), this filter realizes a simple Pan sharpening
 * operation:
 *
 * \f[ \frac{XS}{\mathrm{Filtered}(PAN)} PAN  \f]
 *
43
 * This filter supports streaming and multithreading.
44
45
46
 *
 * \example Fusion/PanSharpeningExample.cxx
 *
47
48
 *
 * \ingroup OTBPanSharpening
49
 */
50
template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision = float>
Emmanuel Christophe's avatar
Emmanuel Christophe committed
51
class ITK_EXPORT SimpleRcsPanSharpeningFusionImageFilter :
OTB Bot's avatar
STYLE    
OTB Bot committed
52
  public itk::ImageToImageFilter<TXsImageType, TOutputImageType>
53
54
{
public:
55
  /** Standard class typedefs */
56
57
58
59
  typedef SimpleRcsPanSharpeningFusionImageFilter                 Self;
  typedef itk::ImageToImageFilter<TXsImageType, TOutputImageType> Superclass;
  typedef itk::SmartPointer<Self>                                 Pointer;
  typedef itk::SmartPointer<const Self>                           ConstPointer;
OTB Bot's avatar
STYLE    
OTB Bot committed
60

61
  /** Internal image type used as the smoothing filter output */
62
  typedef otb::Image<TInternalPrecision,
63
    TPanImageType::ImageDimension>                InternalImageType;
64

65
66
  /** Typedef for the radius of the smoothing filter */
  typedef typename itk::Array<TInternalPrecision> ArrayType;
67

68
69
  /** Method for creation through object factory */
  itkNewMacro(Self);
Emmanuel Christophe's avatar
Emmanuel Christophe committed
70

71
72
73
  /** Run-time type information */
  itkTypeMacro(SimpleRcsPanSharpeningFusionImageFilter,
               itk::ImageToImageFilter);
74

75
  /** Define the radius type for the smoothing operation */
76
  typedef typename InternalImageType::SizeType RadiusType;
77

78
  /** Set the smoothing filter radius  */
OTB Bot's avatar
STYLE    
OTB Bot committed
79
80
  itkGetMacro(Radius, RadiusType);
  itkSetMacro(Radius, RadiusType);
81

82
  /** Set the kernel used for the smoothing filter */
83
84
  itkSetMacro(Filter, ArrayType);
  itkGetConstReferenceMacro(Filter, ArrayType);
85

OTB Bot's avatar
STYLE    
OTB Bot committed
86
  virtual void SetPanInput(const TPanImageType * image);
87
  const TPanImageType * GetPanInput(void) const;
88

OTB Bot's avatar
STYLE    
OTB Bot committed
89
  virtual void SetXsInput(const TXsImageType * path);
90
  const TXsImageType * GetXsInput(void) const;
91

92
protected:
93
  /** Constructor */
94
  SimpleRcsPanSharpeningFusionImageFilter();
Emmanuel Christophe's avatar
Emmanuel Christophe committed
95

96
97
98
  /** Destructor */
  virtual ~SimpleRcsPanSharpeningFusionImageFilter() {};

99
  /** Call to generate data, wiring composite internal minipipeline */
100
  void GenerateData();
Emmanuel Christophe's avatar
Emmanuel Christophe committed
101

102
103
  /** PrintSelf method */
  void PrintSelf(std::ostream& os, itk::Indent indent) const;
Emmanuel Christophe's avatar
Emmanuel Christophe committed
104

105
private:
OTB Bot's avatar
STYLE    
OTB Bot committed
106
107
  SimpleRcsPanSharpeningFusionImageFilter(Self &);   // intentionally not implemented
  void operator =(const Self&);          // intentionally not implemented
Emmanuel Christophe's avatar
Emmanuel Christophe committed
108

109
110
111
  /** \class FusionFunctor
   * This functor applies the
   *  \f[ \frac{XS}{\mathrm{Filtered}(PAN)}PAN  \f]
112
   * operation. It is intended for internal use only.
113
114
 *
 * \ingroup OTBPanSharpening
115
116
117
118
119
   */
  class FusionFunctor
  {
  public:
    // Implement the fusion as a three arguments operator
120
121
122
    typename TOutputImageType::PixelType operator()(const typename TXsImageType::PixelType& xsPixel,
                                                    const TInternalPrecision& smoothPanchroPixel,
                                                    const typename TPanImageType::PixelType& sharpPanchroPixel) const
123
124
125
126
    {
      // Build output pixel
      typename TOutputImageType::PixelType output(xsPixel.Size());

127
128
129
130
131
132
133
      TInternalPrecision scale = 1.;

      if(vcl_abs(smoothPanchroPixel) > 1e-10)
        {
        scale = sharpPanchroPixel/smoothPanchroPixel;
        }

134
135
136
137
      // Perform fusion for each band with appropriate casting
      for(unsigned int i = 0; i < xsPixel.Size(); ++i)
        {
        output[i] = static_cast<typename TOutputImageType::InternalPixelType>(
138
          xsPixel[i] * scale);
139
140
141
142
143
144
145
146
147
148
        }
      // Returns the output pixel
      return output;
    }
  };

  /**
   *  Typedef of the TernaryFunctorImageFilter applying the fusion functor to
   *  p, p_smooth and xs.
   */
149
150
  typedef itk::TernaryFunctorImageFilter<TXsImageType,
                                         InternalImageType,
151
                                         TPanImageType,
152
                                         TOutputImageType,
153
                                         FusionFunctor>     FusionFilterType;
154

155
156
157
  /** Typedef of the convolution filter performing smoothing */
  typedef otb::ConvolutionImageFilter
      <TPanImageType,
158
       InternalImageType,
159
160
       itk::ZeroFluxNeumannBoundaryCondition<TPanImageType>,
       TInternalPrecision>                                  ConvolutionFilterType;
161

162
  /** Pointer to the internal convolution filter */
OTB Bot's avatar
STYLE    
OTB Bot committed
163
  typename ConvolutionFilterType::Pointer m_ConvolutionFilter;
164
165

  /** Pointer to the fusion filter */
166
  typename FusionFilterType::Pointer      m_FusionFilter;
Emmanuel Christophe's avatar
Emmanuel Christophe committed
167

168
  /** Radius used for the smoothing filter */
169
  RadiusType m_Radius;
170
171

  /** Kernel used for the smoothing filter */
OTB Bot's avatar
STYLE    
OTB Bot committed
172
  ArrayType  m_Filter;
173

174
175
  /** The internal progress accumulator */
  typename itk::ProgressAccumulator::Pointer m_ProgressAccumulator;
176
};
177

Emmanuel Christophe's avatar
Emmanuel Christophe committed
178
179
180
181
182
183
184
} // end namespace otb

#ifndef OTB_MANUAL_INSTANTIATION
#include "otbSimpleRcsPanSharpeningFusionImageFilter.txx"
#endif

#endif