OTB  10.0.0
Orfeo Toolbox
otbStreamingStatisticsVectorImageFilter.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 otbStreamingStatisticsVectorImageFilter_h
23 #define otbStreamingStatisticsVectorImageFilter_h
24 
27 #include "itkSimpleDataObjectDecorator.h"
28 #include "itkImageRegionSplitter.h"
29 #include "itkVariableSizeMatrix.h"
30 #include "itkVariableLengthVector.h"
31 
32 namespace otb
33 {
34 
53 template <class TInputImage, class TPrecision>
54 class ITK_EXPORT PersistentStreamingStatisticsVectorImageFilter : public PersistentImageFilter<TInputImage, TInputImage>
55 {
56 public:
60  typedef itk::SmartPointer<Self> Pointer;
61  typedef itk::SmartPointer<const Self> ConstPointer;
62 
64  itkNewMacro(Self);
65 
68 
70  typedef TInputImage ImageType;
71  typedef typename ImageType::Pointer InputImagePointer;
72  typedef typename ImageType::RegionType RegionType;
73  typedef typename ImageType::SizeType SizeType;
74  typedef typename ImageType::IndexType IndexType;
75  typedef typename ImageType::PixelType PixelType;
76  typedef typename ImageType::InternalPixelType InternalPixelType;
77 
78  typedef TPrecision PrecisionType;
80 
82  itkStaticConstMacro(ImageDimension, unsigned int, TInputImage::ImageDimension);
83 
85  typedef typename itk::DataObject::Pointer DataObjectPointer;
86  typedef itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType;
87 
89  typedef itk::VariableSizeMatrix<PrecisionType> MatrixType;
90  typedef itk::VariableLengthVector<PrecisionType> RealPixelType;
91  typedef itk::VariableLengthVector<unsigned long> CountType;
92 
94  typedef itk::SimpleDataObjectDecorator<RealType> RealObjectType;
95  typedef itk::SimpleDataObjectDecorator<IndexType> IndexObjectType;
96  typedef itk::SimpleDataObjectDecorator<PixelType> PixelObjectType;
97  typedef itk::SimpleDataObjectDecorator<RealPixelType> RealPixelObjectType;
98  typedef itk::SimpleDataObjectDecorator<MatrixType> MatrixObjectType;
99  typedef itk::SimpleDataObjectDecorator<CountType> CountObjectType;
100 
103  {
104  return this->GetNbRelevantPixelsOutput()->Get();
105  }
106  CountObjectType* GetNbRelevantPixelsOutput();
107  const CountObjectType* GetNbRelevantPixelsOutput() const;
109 
112  {
113  return this->GetMinOutput()->Get();
114  }
115  PixelObjectType* GetMinimumOutput();
116  const PixelObjectType* GetMinimumOutput() const;
118 
121  {
122  return this->GetMaxOutput()->Get();
123  }
124  PixelObjectType* GetMaximumOutput();
125  const PixelObjectType* GetMaximumOutput() const;
127 
131  {
132  return this->GetComponentMeanOutput()->Get();
133  }
134  RealObjectType* GetComponentMeanOutput();
135  const RealObjectType* GetComponentMeanOutput() const;
137 
141  {
142  return this->GetComponentCorrelationOutput()->Get();
143  }
144  RealObjectType* GetComponentCorrelationOutput();
145  const RealObjectType* GetComponentCorrelationOutput() const;
147 
151  {
152  return this->GetComponentCovarianceOutput()->Get();
153  }
154  RealObjectType* GetComponentCovarianceOutput();
155  const RealObjectType* GetComponentCovarianceOutput() const;
157 
160  {
161  return this->GetMeanOutput()->Get();
162  }
163  RealPixelObjectType* GetMeanOutput();
164  const RealPixelObjectType* GetMeanOutput() const;
166 
169  {
170  return this->GetSumOutput()->Get();
171  }
172  RealPixelObjectType* GetSumOutput();
173  const RealPixelObjectType* GetSumOutput() const;
175 
178  {
179  return this->GetCorrelation()->Get();
180  }
181  MatrixObjectType* GetCorrelationOutput();
182  const MatrixObjectType* GetCorrelationOutput() const;
184 
187  {
188  return this->GetCovarianceOutput()->Get();
189  }
190  MatrixObjectType* GetCovarianceOutput();
191  const MatrixObjectType* GetCovarianceOutput() const;
193 
197  DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override;
198  using Superclass::MakeOutput;
199 
200  void Reset(void) override;
201 
202  void Synthetize(void) override;
203 
204  itkSetMacro(EnableMinMax, bool);
205  itkGetMacro(EnableMinMax, bool);
206 
207  itkSetMacro(EnableFirstOrderStats, bool);
208  itkGetMacro(EnableFirstOrderStats, bool);
209 
210  itkSetMacro(EnableSecondOrderStats, bool);
211  itkGetMacro(EnableSecondOrderStats, bool);
212 
213  itkSetMacro(IgnoreInfiniteValues, bool);
214  itkGetMacro(IgnoreInfiniteValues, bool);
215 
216  itkSetMacro(IgnoreUserDefinedValue, bool);
217  itkGetMacro(IgnoreUserDefinedValue, bool);
218 
219  itkSetMacro(UserIgnoredValue, InternalPixelType);
220  itkGetMacro(UserIgnoredValue, InternalPixelType);
221 
222  itkSetMacro(UseUnbiasedEstimator, bool);
223  itkGetMacro(UseUnbiasedEstimator, bool);
224 
225 protected:
227 
229  {
230  }
231 
235  void AllocateOutputs() override;
236 
237  void GenerateOutputInformation() override;
238 
239  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
240 
242  void ThreadedGenerateData(const RegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
243 
244 private:
246  void operator=(const Self&) = delete;
247 
251 
252 
253  /* use an unbiased estimator to compute the covariance */
255 
256  std::vector<PixelType> m_ThreadMin;
257  std::vector<PixelType> m_ThreadMax;
260  std::vector<RealPixelType> m_ThreadFirstOrderAccumulators;
261  std::vector<MatrixType> m_ThreadSecondOrderAccumulators;
262 
263  /* Ignored values */
267  std::vector<unsigned int> m_IgnoredInfinitePixelCount;
268  std::vector<unsigned int> m_IgnoredUserPixelCount;
269 
270 }; // end of class PersistentStreamingStatisticsVectorImageFilter
271 
296 template <class TInputImage, class TPrecision = typename itk::NumericTraits<typename TInputImage::InternalPixelType>::RealType>
298  : public PersistentFilterStreamingDecorator<PersistentStreamingStatisticsVectorImageFilter<TInputImage, TPrecision>>
299 {
300 public:
304  typedef itk::SmartPointer<Self> Pointer;
305  typedef itk::SmartPointer<const Self> ConstPointer;
306 
308  itkNewMacro(Self);
309 
312 
313  typedef TInputImage InputImageType;
315 
317  typedef typename StatFilterType::PixelType PixelType;
318  typedef typename StatFilterType::RealType RealType;
319  typedef typename StatFilterType::RealObjectType RealObjectType;
320  typedef typename StatFilterType::RealPixelType RealPixelType;
321  typedef typename StatFilterType::RealPixelObjectType RealPixelObjectType;
322  typedef typename StatFilterType::MatrixType MatrixType;
323  typedef typename StatFilterType::MatrixObjectType MatrixObjectType;
324  typedef typename StatFilterType::CountType CountType;
325  typedef typename StatFilterType::CountObjectType CountObjectType;
326 
327  typedef typename StatFilterType::InternalPixelType InternalPixelType;
328 
329  using Superclass::SetInput;
331  {
332  this->GetFilter()->SetInput(input);
333  }
335  {
336  return this->GetFilter()->GetInput();
337  }
338 
341  {
342  return this->GetFilter()->GetNbRelevantPixelsOutput()->Get();
343  }
345  {
346  return this->GetFilter()->GetNbRelevantPixelsOutput();
347  }
349  {
350  return this->GetFilter()->GetNbRelevantPixelsOutput();
351  }
353 
354 
357  {
358  return this->GetFilter()->GetMinimumOutput()->Get();
359  }
361  {
362  return this->GetFilter()->GetMinimumOutput();
363  }
365  {
366  return this->GetFilter()->GetMinimumOutput();
367  }
369 
372  {
373  return this->GetFilter()->GetMaximumOutput()->Get();
374  }
376  {
377  return this->GetFilter()->GetMaximumOutput();
378  }
380  {
381  return this->GetFilter()->GetMaximumOutput();
382  }
384 
387  {
388  return this->GetFilter()->GetMeanOutput()->Get();
389  }
391  {
392  return this->GetFilter()->GetMeanOutput();
393  }
395  {
396  return this->GetFilter()->GetMeanOutput();
397  }
399 
402  {
403  return this->GetFilter()->GetSumOutput()->Get();
404  }
406  {
407  return this->GetFilter()->GetSumOutput();
408  }
410  {
411  return this->GetFilter()->GetSumOutput();
412  }
414 
417  {
418  return this->GetFilter()->GetCovarianceOutput()->Get();
419  }
421  {
422  return this->GetFilter()->GetCovarianceOutput();
423  }
425  {
426  return this->GetFilter()->GetCovarianceOutput();
427  }
429 
432  {
433  return this->GetFilter()->GetCorrelationOutput()->Get();
434  }
436  {
437  return this->GetFilter()->GetCorrelationOutput();
438  }
440  {
441  return this->GetFilter()->GetCorrelationOutput();
442  }
444 
447  {
448  return this->GetFilter()->GetComponentMeanOutput()->Get();
449  }
451  {
452  return this->GetFilter()->GetComponentMeanOutput();
453  }
455  {
456  return this->GetFilter()->GetComponentMeanOutput();
457  }
459 
462  {
463  return this->GetFilter()->GetComponentCovarianceOutput()->Get();
464  }
466  {
467  return this->GetFilter()->GetComponentCovarianceOutput();
468  }
470  {
471  return this->GetFilter()->GetComponentCovarianceOutput();
472  }
474 
477  {
478  return this->GetFilter()->GetComponentCorrelationOutput()->Get();
479  }
481  {
482  return this->GetFilter()->GetComponentCorrelationOutput();
483  }
485  {
486  return this->GetFilter()->GetComponentCorrelationOutput();
487  }
489 
490  otbSetObjectMemberMacro(Filter, EnableMinMax, bool);
491  otbGetObjectMemberMacro(Filter, EnableMinMax, bool);
492 
493  otbSetObjectMemberMacro(Filter, EnableFirstOrderStats, bool);
494  otbGetObjectMemberMacro(Filter, EnableFirstOrderStats, bool);
495 
496  otbSetObjectMemberMacro(Filter, EnableSecondOrderStats, bool);
497  otbGetObjectMemberMacro(Filter, EnableSecondOrderStats, bool);
498 
499  otbSetObjectMemberMacro(Filter, IgnoreInfiniteValues, bool);
500  otbGetObjectMemberMacro(Filter, IgnoreInfiniteValues, bool);
501 
502  otbSetObjectMemberMacro(Filter, IgnoreUserDefinedValue, bool);
503  otbGetObjectMemberMacro(Filter, IgnoreUserDefinedValue, bool);
504 
507 
508  otbSetObjectMemberMacro(Filter, UseUnbiasedEstimator, bool);
509  otbGetObjectMemberMacro(Filter, UseUnbiasedEstimator, bool);
510 
511 protected:
514  {
515  }
516 
519  {
520  }
521 
522 private:
524  void operator=(const Self&) = delete;
525 };
526 
527 } // end namespace otb
528 
529 #ifndef OTB_MANUAL_INSTANTIATION
531 #endif
532 
533 #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 covariance & correlation of a large image using streaming.
PersistentStreamingStatisticsVectorImageFilter(const Self &)=delete
PersistentImageFilter< TInputImage, TInputImage > Superclass
itk::SimpleDataObjectDecorator< RealPixelType > RealPixelObjectType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
This class streams the whole input image through the PersistentStatisticsImageFilter.
otbSetObjectMemberMacro(Filter, EnableSecondOrderStats, bool)
otbGetObjectMemberMacro(Filter, UseUnbiasedEstimator, bool)
otbSetObjectMemberMacro(Filter, UserIgnoredValue, InternalPixelType)
otbGetObjectMemberMacro(Filter, IgnoreInfiniteValues, bool)
otbSetObjectMemberMacro(Filter, IgnoreInfiniteValues, bool)
StreamingStatisticsVectorImageFilter(const Self &)=delete
otbSetObjectMemberMacro(Filter, EnableFirstOrderStats, bool)
otbGetObjectMemberMacro(Filter, EnableSecondOrderStats, bool)
otbGetObjectMemberMacro(Filter, EnableMinMax, bool)
otbSetObjectMemberMacro(Filter, IgnoreUserDefinedValue, bool)
otbGetObjectMemberMacro(Filter, EnableFirstOrderStats, bool)
PersistentFilterStreamingDecorator< PersistentStreamingStatisticsVectorImageFilter< TInputImage, TPrecision > > Superclass
otbGetObjectMemberMacro(Filter, IgnoreUserDefinedValue, bool)
void operator=(const Self &)=delete
otbSetObjectMemberMacro(Filter, UseUnbiasedEstimator, bool)
otbSetObjectMemberMacro(Filter, EnableMinMax, bool)
otbGetObjectMemberMacro(Filter, UserIgnoredValue, InternalPixelType)
static const std::string Filter
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.