OTB  9.0.0
Orfeo Toolbox
otbNormalizeVectorImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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>
30 {
31  m_IsGivenMean = false;
32  m_IsGivenStdDev = false;
33 
34  m_UseMean = true;
35  m_UseStdDev = true;
36 
37  m_CovarianceEstimator = CovarianceEstimatorFilterType::New();
38 }
39 
40 
41 template <class TInputImage, class TOutputImage>
43 {
44  // Call superclass implementation
45  Superclass::GenerateOutputInformation();
46 
47  if ((m_UseMean && !m_IsGivenMean) || (m_UseStdDev && !m_IsGivenStdDev))
48  {
49  m_CovarianceEstimator->SetInput(const_cast<InputImageType*>(this->GetInput()));
50  m_CovarianceEstimator->Update();
51  }
52 
53  if (!m_UseMean)
54  {
55  typename TInputImage::PixelType vector(this->GetInput()->GetNumberOfComponentsPerPixel());
56  vector.Fill(itk::NumericTraits<typename TInputImage::PixelType::ValueType>::Zero);
57  this->GetFunctor().SetMean(vector);
58  }
59 
60  if (!m_UseStdDev)
61  {
62  typename TInputImage::PixelType vector(this->GetInput()->GetNumberOfComponentsPerPixel());
63  vector.Fill(itk::NumericTraits<typename TInputImage::PixelType::ValueType>::One);
64  this->GetFunctor().SetStdDev(vector);
65  }
66 
67  if (!m_IsGivenMean)
68  {
69  this->GetFunctor().SetMean(m_CovarianceEstimator->GetMean());
70 
71  if (!m_IsGivenStdDev && m_UseStdDev)
72  {
73  typename StreamingStatisticsVectorImageFilter<InputImageType>::RealPixelType sigma(this->GetInput()->GetNumberOfComponentsPerPixel());
74  for (unsigned int i = 0; i < sigma.Size(); ++i)
75  sigma[i] = std::sqrt(m_CovarianceEstimator->GetCovariance()(i, i));
76 
77  this->GetFunctor().SetStdDev(sigma);
78  }
79  }
80 }
81 
82 } // end of namespace otb
83 
84 #endif // otbNormalizeVectorImageFilter_hxx
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::StreamingStatisticsVectorImageFilter::RealPixelType
StatFilterType::RealPixelType RealPixelType
Definition: otbStreamingStatisticsVectorImageFilter.h:320
otbNormalizeVectorImageFilter.h
otb::NormalizeVectorImageFilter::GenerateOutputInformation
void GenerateOutputInformation() override
Definition: otbNormalizeVectorImageFilter.hxx:42
otb::NormalizeVectorImageFilter::NormalizeVectorImageFilter
NormalizeVectorImageFilter()
Definition: otbNormalizeVectorImageFilter.hxx:29
otb::NormalizeVectorImageFilter::InputImageType
TInputImage InputImageType
Definition: otbNormalizeVectorImageFilter.h:149