OTB  10.0.0
Orfeo Toolbox
otbStreamingStatisticsImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbStreamingStatisticsImageFilter_h
23 #define otbStreamingStatisticsImageFilter_h
24 
26 #include "itkNumericTraits.h"
27 #include "itkArray.h"
28 #include "itkSimpleDataObjectDecorator.h"
30 
31 namespace otb
32 {
33 
51 template <class TInputImage>
52 class ITK_EXPORT PersistentStatisticsImageFilter : public PersistentImageFilter<TInputImage, TInputImage>
53 {
54 public:
58  typedef itk::SmartPointer<Self> Pointer;
59  typedef itk::SmartPointer<const Self> ConstPointer;
60 
62  itkNewMacro(Self);
63 
66 
68  typedef TInputImage ImageType;
69  typedef typename TInputImage::Pointer InputImagePointer;
70 
71  typedef typename TInputImage::RegionType RegionType;
72  typedef typename TInputImage::SizeType SizeType;
73  typedef typename TInputImage::IndexType IndexType;
74  typedef typename TInputImage::PixelType PixelType;
75 
76  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
77 
79  itkStaticConstMacro(ImageDimension, unsigned int, TInputImage::ImageDimension);
80 
82  typedef typename itk::NumericTraits<PixelType>::RealType RealType;
83 
85  typedef typename itk::DataObject::Pointer DataObjectPointer;
86  typedef itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType;
87 
89  typedef itk::SimpleDataObjectDecorator<RealType> RealObjectType;
90  typedef itk::SimpleDataObjectDecorator<PixelType> PixelObjectType;
91 
94  {
95  return this->GetMinimumOutput()->Get();
96  }
97  PixelObjectType* GetMinimumOutput();
98  const PixelObjectType* GetMinimumOutput() const;
100 
103  {
104  return this->GetMaximumOutput()->Get();
105  }
106  PixelObjectType* GetMaximumOutput();
107  const PixelObjectType* GetMaximumOutput() const;
109 
112  {
113  return this->GetMeanOutput()->Get();
114  }
115  RealObjectType* GetMeanOutput();
116  const RealObjectType* GetMeanOutput() const;
118 
121  {
122  return this->GetSigmaOutput()->Get();
123  }
124  RealObjectType* GetSigmaOutput();
125  const RealObjectType* GetSigmaOutput() const;
127 
130  {
131  return this->GetVarianceOutput()->Get();
132  }
133  RealObjectType* GetVarianceOutput();
134  const RealObjectType* GetVarianceOutput() const;
136 
138  RealType GetSum() const
139  {
140  return this->GetSumOutput()->Get();
141  }
142  RealObjectType* GetSumOutput();
143  const RealObjectType* GetSumOutput() const;
145 
148  DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override;
149  using Superclass::MakeOutput;
150 
154  void AllocateOutputs() override;
155  void GenerateOutputInformation() override;
156  void Synthetize(void) override;
157  void Reset(void) override;
159 
160  itkSetMacro(IgnoreInfiniteValues, bool);
161  itkGetMacro(IgnoreInfiniteValues, bool);
162 
163  itkSetMacro(IgnoreUserDefinedValue, bool);
164  itkGetMacro(IgnoreUserDefinedValue, bool);
165 
166  itkSetMacro(UserIgnoredValue, RealType);
167  itkGetMacro(UserIgnoredValue, RealType);
168 
169 protected:
172  {
173  }
174  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
175 
177  void ThreadedGenerateData(const RegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
178 
179 private:
181  void operator=(const Self&) = delete;
182 
183  itk::Array<RealType> m_ThreadSum;
184  itk::Array<RealType> m_SumOfSquares;
185  itk::Array<long> m_Count;
186  itk::Array<PixelType> m_ThreadMin;
187  itk::Array<PixelType> m_ThreadMax;
188 
189  /* Ignored values */
193  std::vector<unsigned int> m_IgnoredInfinitePixelCount;
194  std::vector<unsigned int> m_IgnoredUserPixelCount;
195 
196 
197 }; // end of class PersistentStatisticsImageFilter
198 
199 /*===========================================================================*/
200 
233 template <class TInputImage>
234 class ITK_EXPORT StreamingStatisticsImageFilter : public PersistentFilterStreamingDecorator<PersistentStatisticsImageFilter<TInputImage>>
235 {
236 public:
240  typedef itk::SmartPointer<Self> Pointer;
241  typedef itk::SmartPointer<const Self> ConstPointer;
242 
244  itkNewMacro(Self);
245 
248 
252  typedef TInputImage InputImageType;
253 
255  typedef itk::SimpleDataObjectDecorator<RealType> RealObjectType;
256  typedef itk::SimpleDataObjectDecorator<PixelType> PixelObjectType;
257 
258  using Superclass::SetInput;
260  {
261  this->GetFilter()->SetInput(input);
262  }
264  {
265  return this->GetFilter()->GetInput();
266  }
267 
270  {
271  return this->GetFilter()->GetMinimumOutput()->Get();
272  }
274  {
275  return this->GetFilter()->GetMinimumOutput();
276  }
278  {
279  return this->GetFilter()->GetMinimumOutput();
280  }
281 
284  {
285  return this->GetFilter()->GetMaximumOutput()->Get();
286  }
288  {
289  return this->GetFilter()->GetMaximumOutput();
290  }
292  {
293  return this->GetFilter()->GetMaximumOutput();
294  }
295 
298  {
299  return this->GetFilter()->GetMeanOutput()->Get();
300  }
302  {
303  return this->GetFilter()->GetMeanOutput();
304  }
306  {
307  return this->GetFilter()->GetMeanOutput();
308  }
310 
313  {
314  return this->GetSigmaOutput()->Get();
315  }
317  {
318  return this->GetFilter()->GetSigmaOutput();
319  }
321  {
322  return this->GetFilter()->GetSigmaOutput();
323  }
325 
328  {
329  return this->GetFilter()->GetVarianceOutput()->Get();
330  }
332  {
333  return this->GetFilter()->GetVarianceOutput();
334  }
336  {
337  return this->GetFilter()->GetVarianceOutput();
338  }
340 
342  RealType GetSum() const
343  {
344  return this->GetFilter()->GetSumOutput()->Get();
345  }
347  {
348  return this->GetFilter()->GetSumOutput();
349  }
351  {
352  return this->GetFilter()->GetSumOutput();
353  }
355 
356  otbSetObjectMemberMacro(Filter, IgnoreInfiniteValues, bool);
357  otbGetObjectMemberMacro(Filter, IgnoreInfiniteValues, bool);
358 
359  otbSetObjectMemberMacro(Filter, IgnoreUserDefinedValue, bool);
360  otbGetObjectMemberMacro(Filter, IgnoreUserDefinedValue, bool);
361 
364 
365 protected:
368 
371  {
372  }
373 
374 private:
376  void operator=(const Self&) = delete;
377 };
378 
379 } // end namespace otb
380 
381 #ifndef OTB_MANUAL_INSTANTIATION
383 #endif
384 
385 #endif
This filter link a persistent filter with a StreamingImageVirtualWriter.
This filter is the base class for all filter persisting data through multiple update....
Compute min. max, variance and mean of an image using the output requested region.
itk::SimpleDataObjectDecorator< PixelType > PixelObjectType
itk::SimpleDataObjectDecorator< RealType > RealObjectType
PersistentImageFilter< TInputImage, TInputImage > Superclass
itk::NumericTraits< PixelType >::RealType RealType
void operator=(const Self &)=delete
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
PersistentStatisticsImageFilter(const Self &)=delete
This class streams the whole input image through the PersistentStatisticsImageFilter.
PersistentFilterStreamingDecorator< PersistentStatisticsImageFilter< TInputImage > > Superclass
otbSetObjectMemberMacro(Filter, IgnoreInfiniteValues, bool)
itk::SimpleDataObjectDecorator< PixelType > PixelObjectType
otbGetObjectMemberMacro(Filter, IgnoreUserDefinedValue, bool)
otbGetObjectMemberMacro(Filter, IgnoreInfiniteValues, bool)
itk::SimpleDataObjectDecorator< RealType > RealObjectType
StreamingStatisticsImageFilter(const Self &)=delete
otbGetObjectMemberMacro(Filter, UserIgnoredValue, RealType)
otbSetObjectMemberMacro(Filter, IgnoreUserDefinedValue, bool)
otbSetObjectMemberMacro(Filter, UserIgnoredValue, RealType)
void operator=(const Self &)=delete
static const std::string Filter
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.