OTB  6.7.0
Orfeo Toolbox
otbNormalizeVectorImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbNormalizeVectorImageFilter_hxx
22 #define otbNormalizeVectorImageFilter_hxx
24 
25 namespace otb
26 {
27 
28 template < class TInputImage, class TOutputImage >
31 {
32  m_IsGivenMean = false;
33  m_IsGivenStdDev = false;
34 
35  m_UseMean = true;
36  m_UseStdDev = true;
37 
38  m_CovarianceEstimator = CovarianceEstimatorFilterType::New();
39 }
40 
41 
42 template < class TInputImage, class TOutputImage >
43 void
46 {
47  // Call superclass implementation
48  Superclass::GenerateOutputInformation();
49 
50  if( (m_UseMean && !m_IsGivenMean) || (m_UseStdDev && !m_IsGivenStdDev))
51  {
52  m_CovarianceEstimator->SetInput( const_cast<InputImageType*>( this->GetInput() ) );
53  m_CovarianceEstimator->Update();
54  }
55 
56  if ( !m_UseMean )
57  {
58  typename TInputImage::PixelType vector ( this->GetInput()->GetNumberOfComponentsPerPixel() );
60  this->GetFunctor().SetMean( vector );
61  }
62 
63  if ( !m_UseStdDev )
64  {
65  typename TInputImage::PixelType vector ( this->GetInput()->GetNumberOfComponentsPerPixel() );
67  this->GetFunctor().SetStdDev( vector );
68  }
69 
70  if ( !m_IsGivenMean )
71  {
72  this->GetFunctor().SetMean( m_CovarianceEstimator->GetMean() );
73 
74  if ( !m_IsGivenStdDev && m_UseStdDev )
75  {
77  ( this->GetInput()->GetNumberOfComponentsPerPixel() );
78  for ( unsigned int i = 0; i < sigma.Size(); ++i )
79  sigma[i] = std::sqrt( m_CovarianceEstimator->GetCovariance()(i, i) );
80 
81  this->GetFunctor().SetStdDev( sigma );
82  }
83  }
84 
85 }
86 
87 } // end of namespace otb
88 
89 #endif // otbNormalizeVectorImageFilter_hxx