OTB  9.0.0
Orfeo Toolbox
otbMeanFilterFunctor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of S1Tiling remote module for 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 otbMeanFilterFunctor_h
22 #define otbMeanFilterFunctor_h
23 
24 #include "itkNumericTraits.h"
25 
26 namespace otb
27 {
28 
29 namespace Functor
30 {
31 
42 template<class TInput1, class TOutput>
44 {
45  using PixelNumericType = typename itk::NumericTraits<TOutput>::ValueType;
46 public:
47  MeanFilterFunctor() = default;
48  TOutput operator ()(const TInput1& itA) const
49  {
50  TOutput meanA=static_cast<TOutput>(0.0);
51  meanA[0]=0.;
53 
54  int non_zeros_pixels = 0;
55  for (unsigned long pos = 0; pos < itA.Size(); ++pos)
56  {
57  if (itA.GetPixel(pos)[0]!=0.)
58  {
59  meanA[0] += itA.GetPixel(pos)[0];
60  ++non_zeros_pixels;
61  }
62  }
63 
64  if (non_zeros_pixels > 0)
65  {
66  meanA[0] /= static_cast<PixelNumericType>(non_zeros_pixels);
67  }
68  else
69  {
70  meanA[0] = 0.;
71  }
72 
73  //std::cout<<"meanA= "<<meanA<<", meanB= "<<meanB<<std::endl;
74 
75  TOutput ratio=itA.GetCenterPixel();
76  if (ratio[0]!=0.)
77  {
78  ratio[0]=meanA[0];
79  }
80  //std::cout<<ratio[0]<<"\n";
81  return static_cast<TOutput>(ratio);
82  }
83 };
84 }
85 } // end namespace otb
86 
87 #endif
otb::Functor::MeanFilterFunctor::operator()
TOutput operator()(const TInput1 &itA) const
Definition: otbMeanFilterFunctor.h:48
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::MeanFilterFunctor
Definition: otbMeanFilterFunctor.h:43
otb::Functor::MeanFilterFunctor::MeanFilterFunctor
MeanFilterFunctor()=default
otb::Functor::MeanFilterFunctor< itk::ConstNeighborhoodIterator< TInputImage1 >, TOutputImage::PixelType >::PixelNumericType
typename itk::NumericTraits< TOutputImage::PixelType >::ValueType PixelNumericType
Definition: otbMeanFilterFunctor.h:45