OTB  9.0.0
Orfeo Toolbox
otbOutcoreFunctor.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 otbOutcoreFunctor_h
22 #define otbOutcoreFunctor_h
23 
24 namespace otb
25 {
26 
27 namespace Functor
28 {
29 
37 template<class TInput, class TOutput>
39 {
40 public:
41  OutcoreFunctor() = default;
42  ~OutcoreFunctor() = default;
43  TOutput operator ()(const TInput& itA) const
44  {
45  TOutput meanA;
46  meanA.SetSize(1);
47  meanA.Fill(0.);
48  TOutput pixel;
49  pixel.SetSize(1);
51 
52  TOutput nb_non_zero_pixels;
53  nb_non_zero_pixels.SetSize(1);
54  nb_non_zero_pixels.Fill(0.);
55 
56  for (unsigned long pos = 0; pos < itA.Size(); ++pos)
57  {
58  pixel = itA.GetPixel(pos);
59  meanA += pixel;
60  for (unsigned long i = 0; i < pixel.Size(); ++i)
61  {
62  if (pixel[i] != 0.)
63  {
64  nb_non_zero_pixels[i]++;
65  }
66  }
67  }
68  for (unsigned long i = 0; i < pixel.Size(); ++i)
69  {
70  if (nb_non_zero_pixels[i] !=0.)
71  {
72  meanA[i] /= nb_non_zero_pixels[i];
73  }
74  else
75  {
76  meanA[i]=0.;
77  }
78  }
79 
80  TOutput ratio=itA.GetCenterPixel();
81  ratio.SetSize(meanA.GetSize()+1); // add an element to store the ENL (nb of images used for temporal average)
82 
83  for (unsigned long i = 0; i < meanA.Size(); ++i)
84  {
85  if ((meanA[i]!=0.)&&(ratio[i]!=0.))
86  {
87  ratio[i]/=meanA[i];
88  }
89  else
90  {
91  ratio[i]=0.;
92  }
93  // Compute the ENL (nb of images used for temporal average)
94  ratio[meanA.Size()]=int(ratio[0]>0.);
95  }
96  return static_cast<TOutput>(ratio);
97  }
98 };
99 }
100 } // end namespace otb
101 
102 #endif
otb::Functor::OutcoreFunctor
Definition: otbOutcoreFunctor.h:38
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::OutcoreFunctor::OutcoreFunctor
OutcoreFunctor()=default
otb::Functor::OutcoreFunctor::operator()
TOutput operator()(const TInput &itA) const
Definition: otbOutcoreFunctor.h:43
otb::Functor::OutcoreFunctor::~OutcoreFunctor
~OutcoreFunctor()=default