otbReciprocalBarnesDecompImageFilter.h 4.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
20 21


22 23
#ifndef otbReciprocalBarnesDecompImageFilter_h
#define otbReciprocalBarnesDecompImageFilter_h
24 25 26 27 28

#include "otbMath.h"
#include "vnl/algo/vnl_complex_eigensystem.h"
#include <algorithm>

29 30
#include "otbFunctorImageFilter.h"

31 32 33 34 35 36
namespace otb
 {

namespace Functor {

/** \class otbBarnesDecompFunctor
37
 *
38
 * \brief Evaluate the Huynen decomposition from the reciprocal Sinclair matrix image.
39
 *
40 41
 * Use otb::BarnesDecompImageFilter to apply
 *
42 43 44 45 46 47 48 49 50 51 52 53 54
 * \ingroup OTBPolarimetry
 */
template< class TInput, class TOutput>
class ReciprocalBarnesDecompFunctor
{
public:
  typedef typename std::complex<double> ComplexType;
  typedef vnl_matrix<ComplexType>       VNLMatrixType;
  typedef vnl_vector<ComplexType>       VNLVectorType;
  typedef vnl_vector<double>           VNLDoubleVectorType;
  typedef std::vector<double>           VectorType;
  typedef typename TOutput::ValueType   OutputValueType;

55
  inline void operator()(TOutput& result, const TInput& Covariance) const
56 57
  {

58
    VNLMatrixType qi(3, 1);
59 60 61 62 63 64 65 66 67 68 69 70 71 72


    VNLMatrixType cov(3, 3);
    cov[0][0] = ComplexType(Covariance[0]);
    cov[0][1] = ComplexType(Covariance[1]);
    cov[0][2] = ComplexType(Covariance[2]);
    cov[1][0] = std::conj(ComplexType(Covariance[1]));
    cov[1][1] = ComplexType(Covariance[3]);
    cov[1][2] = ComplexType(Covariance[4]);
    cov[2][0] = std::conj(ComplexType(Covariance[2]));
    cov[2][1] = std::conj(ComplexType(Covariance[4]));
    cov[2][2] = ComplexType(Covariance[5]);


73 74 75 76 77
    qi[0][0]           = ComplexType(1., 0.);
    qi[1][0]           = ComplexType(0., 0.);
    qi[2][0]           = ComplexType(0., 0.);
    ComplexType   norm = (qi.conjugate_transpose() * cov * qi)[0][0];
    VNLMatrixType ki   = cov * qi / std::sqrt(norm);
78 79 80
    result[0] = static_cast<OutputValueType>(ki[0][0]);
    result[1] = static_cast<OutputValueType>(ki[1][0]);
    result[2] = static_cast<OutputValueType>(ki[2][0]);
81 82


83 84 85 86 87
    qi[0][0]  = ComplexType(0., 0.);
    qi[1][0]  = ComplexType(1. / std::sqrt(2.), 0.);
    qi[2][0]  = ComplexType(0., 1. / std::sqrt(2.));
    norm      = (qi.conjugate_transpose() * cov * qi)[0][0];
    ki        = cov * qi / std::sqrt(norm);
88 89 90
    result[3] = static_cast<OutputValueType>(ki[0][0]);
    result[4] = static_cast<OutputValueType>(ki[1][0]);
    result[5] = static_cast<OutputValueType>(ki[2][0]);
91 92


93
    qi[0][0]=ComplexType(0.,0.);
94 95 96 97
    qi[1][0]  = ComplexType(0., 1. / std::sqrt(2.));
    qi[2][0]  = ComplexType(1. / std::sqrt(2.), 0.);
    norm      = (qi.conjugate_transpose() * cov * qi)[0][0];
    ki        = cov * qi / std::sqrt(norm);
98 99 100
    result[6] = static_cast<OutputValueType>(ki[0][0]);
    result[7] = static_cast<OutputValueType>(ki[1][0]);
    result[8] = static_cast<OutputValueType>(ki[2][0]);
101
  }
102

103 104 105 106 107
  constexpr size_t OutputSize(...) const
  {
    // Size of the result
    return 9;
  }
108

109
private:
110
  static constexpr double m_Epsilon = 1e-6;
111
};
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
} // namespace Functor

/**
 * \typedef ReciprocalBarnesDecompImageFilter
 * \brief Applies otb::Functor::ReciprocalBarnesDecompFunctor
 * \sa otb::Functor::ReciprocalBarnesDecompFunctor
 *
 * Set inputs with:
 * \code
 * SetVariadicInput<0>(inputPtr);
 * \endcode
 *
 * \ingroup OTBPolarimetry
 */
template <typename TInputImage, typename TOutputImage>
127
using ReciprocalBarnesDecompImageFilter =
128
    FunctorImageFilter<Functor::ReciprocalBarnesDecompFunctor<typename TInputImage::PixelType, typename TOutputImage::PixelType>>;
129 130 131
} // end namespace otb

#endif