OTB  7.4.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-2020 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;
74  typedef typename TInputImage::PixelType PixelType;
75 
76  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
77 
79  itkStaticConstMacro(ImageDimension, unsigned int, TInputImage::ImageDimension);
80 
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 
93  PixelType GetMinimum() const
94  {
95  return this->GetMinimumOutput()->Get();
96  }
97  PixelObjectType* GetMinimumOutput();
98  const PixelObjectType* GetMinimumOutput() const;
100 
102  PixelType GetMaximum() const
103  {
104  return this->GetMaximumOutput()->Get();
105  }
106  PixelObjectType* GetMaximumOutput();
107  const PixelObjectType* GetMaximumOutput() const;
109 
111  RealType GetMean() const
112  {
113  return this->GetMeanOutput()->Get();
114  }
115  RealObjectType* GetMeanOutput();
116  const RealObjectType* GetMeanOutput() const;
118 
120  RealType GetSigma() const
121  {
122  return this->GetSigmaOutput()->Get();
123  }
124  RealObjectType* GetSigmaOutput();
125  const RealObjectType* GetSigmaOutput() const;
127 
129  RealType GetVariance() const
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:
180  PersistentStatisticsImageFilter(const Self&) = delete;
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 
249  typedef typename Superclass::FilterType StatFilterType;
252  typedef TInputImage InputImageType;
253 
255  typedef itk::SimpleDataObjectDecorator<RealType> RealObjectType;
256  typedef itk::SimpleDataObjectDecorator<PixelType> PixelObjectType;
257 
258  using Superclass::SetInput;
259  void SetInput(InputImageType* input)
260  {
261  this->GetFilter()->SetInput(input);
262  }
263  const InputImageType* GetInput()
264  {
265  return this->GetFilter()->GetInput();
266  }
267 
269  PixelType GetMinimum() const
270  {
271  return this->GetFilter()->GetMinimumOutput()->Get();
272  }
273  PixelObjectType* GetMinimumOutput()
274  {
275  return this->GetFilter()->GetMinimumOutput();
276  }
277  const PixelObjectType* GetMinimumOutput() const
278  {
279  return this->GetFilter()->GetMinimumOutput();
280  }
281 
283  PixelType GetMaximum() const
284  {
285  return this->GetFilter()->GetMaximumOutput()->Get();
286  }
287  PixelObjectType* GetMaximumOutput()
288  {
289  return this->GetFilter()->GetMaximumOutput();
290  }
291  const PixelObjectType* GetMaximumOutput() const
292  {
293  return this->GetFilter()->GetMaximumOutput();
294  }
295 
297  RealType GetMean() const
298  {
299  return this->GetFilter()->GetMeanOutput()->Get();
300  }
301  RealObjectType* GetMeanOutput()
302  {
303  return this->GetFilter()->GetMeanOutput();
304  }
305  const RealObjectType* GetMeanOutput() const
306  {
307  return this->GetFilter()->GetMeanOutput();
308  }
310 
312  RealType GetSigma() const
313  {
314  return this->GetSigmaOutput()->Get();
315  }
316  RealObjectType* GetSigmaOutput()
317  {
318  return this->GetFilter()->GetSigmaOutput();
319  }
320  const RealObjectType* GetSigmaOutput() const
321  {
322  return this->GetFilter()->GetSigmaOutput();
323  }
325 
327  RealType GetVariance() const
328  {
329  return this->GetFilter()->GetVarianceOutput()->Get();
330  }
331  RealObjectType* GetVarianceOutput()
332  {
333  return this->GetFilter()->GetVarianceOutput();
334  }
335  const RealObjectType* GetVarianceOutput() const
336  {
337  return this->GetFilter()->GetVarianceOutput();
338  }
340 
342  RealType GetSum() const
343  {
344  return this->GetFilter()->GetSumOutput()->Get();
345  }
346  RealObjectType* GetSumOutput()
347  {
348  return this->GetFilter()->GetSumOutput();
349  }
350  const RealObjectType* GetSumOutput() const
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 
362  otbSetObjectMemberMacro(Filter, UserIgnoredValue, RealType);
363  otbGetObjectMemberMacro(Filter, UserIgnoredValue, RealType);
364 
365 protected:
368 
371  {
372  }
373 
374 private:
375  StreamingStatisticsImageFilter(const Self&) = delete;
376  void operator=(const Self&) = delete;
377 };
378 
379 } // end namespace otb
380 
381 #ifndef OTB_MANUAL_INSTANTIATION
383 #endif
384 
385 #endif
itk::Size< Monteverdi_DIMENSION > SizeType
Definition: mvdTypes.h:137
Compute min. max, variance and mean of an image using the output requested region.
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:133
itk::SimpleDataObjectDecorator< RealType > RealObjectType
#define otbGetObjectMemberMacro(object, name, type)
Definition: otbMacro.h:89
itk::SimpleDataObjectDecorator< RealType > RealObjectType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
static const std::string Filter
PersistentImageFilter< TInputImage, TInputImage > Superclass
itk::SimpleDataObjectDecorator< PixelType > PixelObjectType
This class streams the whole input image through the PersistentStatisticsImageFilter.
Monteverdi_FLOATING_TYPE RealType
Definition: mvdTypes.h:84
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
itk::SimpleDataObjectDecorator< PixelType > PixelObjectType
#define otbSetObjectMemberMacro(object, name, type)
Definition: otbMacro.h:79
PersistentFilterStreamingDecorator< PersistentStatisticsImageFilter< TInputImage > > Superclass
itk::NumericTraits< PixelType >::RealType RealType
This filter is the base class for all filter persisting data through multiple update. For instance, a filter computing global statistics on an image with streaming capabilities will have to keep the temporary results for each streamed piece of the image in order to synthesize the global statistics at the end. This filter is an itk::ImageToImageFilter, providing two additional methods. The first one, Synthetize(), allows the user to synthesize temporary data produced by the multiple updates on different pieces of the image to the global result. The second one, Reset(), allows the user to reset the temporary data for a new input image for instance.
This filter link a persistent filter with a StreamingImageVirtualWriter.