OTB  7.2.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-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 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;
79  typedef PrecisionType RealType;
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 
102  CountType GetNbRelevantPixels() const
103  {
104  return this->GetNbRelevantPixelsOutput()->Get();
105  }
106  CountObjectType* GetNbRelevantPixelsOutput();
107  const CountObjectType* GetNbRelevantPixelsOutput() const;
109 
111  PixelType GetMinimum() const
112  {
113  return this->GetMinOutput()->Get();
114  }
115  PixelObjectType* GetMinimumOutput();
116  const PixelObjectType* GetMinimumOutput() const;
118 
120  PixelType GetMaximum() const
121  {
122  return this->GetMaxOutput()->Get();
123  }
124  PixelObjectType* GetMaximumOutput();
125  const PixelObjectType* GetMaximumOutput() const;
127 
130  RealType GetComponentMean() const
131  {
132  return this->GetComponentMeanOutput()->Get();
133  }
134  RealObjectType* GetComponentMeanOutput();
135  const RealObjectType* GetComponentMeanOutput() const;
137 
140  RealType GetComponentCorrelation() const
141  {
142  return this->GetComponentCorrelationOutput()->Get();
143  }
144  RealObjectType* GetComponentCorrelationOutput();
145  const RealObjectType* GetComponentCorrelationOutput() const;
147 
150  RealType GetComponentCovariance() const
151  {
152  return this->GetComponentCovarianceOutput()->Get();
153  }
154  RealObjectType* GetComponentCovarianceOutput();
155  const RealObjectType* GetComponentCovarianceOutput() const;
157 
159  RealPixelType GetMean() const
160  {
161  return this->GetMeanOutput()->Get();
162  }
163  RealPixelObjectType* GetMeanOutput();
164  const RealPixelObjectType* GetMeanOutput() const;
166 
168  RealPixelType GetSum() const
169  {
170  return this->GetSumOutput()->Get();
171  }
172  RealPixelObjectType* GetSumOutput();
173  const RealPixelObjectType* GetSumOutput() const;
175 
177  MatrixType GetCorrelation() const
178  {
179  return this->GetCorrelation()->Get();
180  }
181  MatrixObjectType* GetCorrelationOutput();
182  const MatrixObjectType* GetCorrelationOutput() const;
184 
186  MatrixType GetCovariance() const
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 */
266  InternalPixelType m_UserIgnoredValue;
267  std::vector<unsigned int> m_IgnoredInfinitePixelCount;
268  std::vector<unsigned int> m_IgnoredUserPixelCount;
269 
270 }; // end of class PersistentStreamingStatisticsVectorImageFilter
271 
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;
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;
325  typedef typename StatFilterType::CountObjectType CountObjectType;
326 
327  typedef typename StatFilterType::InternalPixelType InternalPixelType;
328 
329  using Superclass::SetInput;
330  void SetInput(InputImageType* input)
331  {
332  this->GetFilter()->SetInput(input);
333  }
334  const InputImageType* GetInput()
335  {
336  return this->GetFilter()->GetInput();
337  }
338 
340  CountType GetNbRelevantPixels() const
341  {
342  return this->GetFilter()->GetNbRelevantPixelsOutput()->Get();
343  }
344  CountObjectType* GetNbRelevantPixelsOutput()
345  {
346  return this->GetFilter()->GetNbRelevantPixelsOutput();
347  }
348  const CountObjectType* GetNbRelevantPixelsOutput() const
349  {
350  return this->GetFilter()->GetNbRelevantPixelsOutput();
351  }
353 
354 
356  RealPixelType GetMinimum() const
357  {
358  return this->GetFilter()->GetMinimumOutput()->Get();
359  }
360  RealPixelObjectType* GetMinimumOutput()
361  {
362  return this->GetFilter()->GetMinimumOutput();
363  }
364  const RealPixelObjectType* GetMinimumOutput() const
365  {
366  return this->GetFilter()->GetMinimumOutput();
367  }
369 
371  RealPixelType GetMaximum() const
372  {
373  return this->GetFilter()->GetMaximumOutput()->Get();
374  }
375  RealPixelObjectType* GetMaximumOutput()
376  {
377  return this->GetFilter()->GetMaximumOutput();
378  }
379  const RealPixelObjectType* GetMaximumOutput() const
380  {
381  return this->GetFilter()->GetMaximumOutput();
382  }
384 
386  RealPixelType GetMean() const
387  {
388  return this->GetFilter()->GetMeanOutput()->Get();
389  }
390  RealPixelObjectType* GetMeanOutput()
391  {
392  return this->GetFilter()->GetMeanOutput();
393  }
394  const RealPixelObjectType* GetMeanOutput() const
395  {
396  return this->GetFilter()->GetMeanOutput();
397  }
399 
401  RealPixelType GetSum() const
402  {
403  return this->GetFilter()->GetSumOutput()->Get();
404  }
405  RealPixelObjectType* GetSumOutput()
406  {
407  return this->GetFilter()->GetSumOutput();
408  }
409  const RealPixelObjectType* GetSumOutput() const
410  {
411  return this->GetFilter()->GetSumOutput();
412  }
414 
416  MatrixType GetCovariance() const
417  {
418  return this->GetFilter()->GetCovarianceOutput()->Get();
419  }
420  MatrixObjectType* GetCovarianceOutput()
421  {
422  return this->GetFilter()->GetCovarianceOutput();
423  }
424  const MatrixObjectType* GetCovarianceOutput() const
425  {
426  return this->GetFilter()->GetCovarianceOutput();
427  }
429 
431  MatrixType GetCorrelation() const
432  {
433  return this->GetFilter()->GetCorrelationOutput()->Get();
434  }
435  MatrixObjectType* GetCorrelationOutput()
436  {
437  return this->GetFilter()->GetCorrelationOutput();
438  }
439  const MatrixObjectType* GetCorrelationOutput() const
440  {
441  return this->GetFilter()->GetCorrelationOutput();
442  }
444 
446  RealType GetComponentMean() const
447  {
448  return this->GetFilter()->GetComponentMeanOutput()->Get();
449  }
450  RealObjectType* GetComponentMeanOutput()
451  {
452  return this->GetFilter()->GetComponentMeanOutput();
453  }
454  const RealObjectType* GetComponentMeanOutput() const
455  {
456  return this->GetFilter()->GetComponentMeanOutput();
457  }
459 
461  RealType GetComponentCovariance() const
462  {
463  return this->GetFilter()->GetComponentCovarianceOutput()->Get();
464  }
466  {
467  return this->GetFilter()->GetComponentCovarianceOutput();
468  }
469  const RealObjectType* GetComponentCovarianceOutput() const
470  {
471  return this->GetFilter()->GetComponentCovarianceOutput();
472  }
474 
476  RealType GetComponentCorrelation() const
477  {
478  return this->GetFilter()->GetComponentCorrelationOutput()->Get();
479  }
481  {
482  return this->GetFilter()->GetComponentCorrelationOutput();
483  }
484  const RealObjectType* GetComponentCorrelationOutput() const
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 
505  otbSetObjectMemberMacro(Filter, UserIgnoredValue, InternalPixelType);
506  otbGetObjectMemberMacro(Filter, UserIgnoredValue, InternalPixelType);
507 
508  otbSetObjectMemberMacro(Filter, UseUnbiasedEstimator, bool);
509  otbGetObjectMemberMacro(Filter, UseUnbiasedEstimator, bool);
510 
511 protected:
514  {
515  }
516 
519  {
520  }
521 
522 private:
523  StreamingStatisticsVectorImageFilter(const Self&) = delete;
524  void operator=(const Self&) = delete;
525 };
526 
527 } // end namespace otb
528 
529 #ifndef OTB_MANUAL_INSTANTIATION
531 #endif
532 
533 #endif
itk::Size< Monteverdi_DIMENSION > SizeType
Definition: mvdTypes.h:137
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:133
PersistentFilterStreamingDecorator< PersistentStreamingStatisticsVectorImageFilter< TInputImage, TPrecision > > Superclass
Compute covariance & correlation of a large image using streaming.
PersistentImageFilter< TInputImage, TInputImage > Superclass
#define otbGetObjectMemberMacro(object, name, type)
Definition: otbMacro.h:89
unsigned int CountType
Definition: mvdTypes.h:80
itk::SimpleDataObjectDecorator< RealPixelType > RealPixelObjectType
static const std::string Filter
Monteverdi_FLOATING_TYPE RealType
Definition: mvdTypes.h:84
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
#define otbSetObjectMemberMacro(object, name, type)
Definition: otbMacro.h:79
This class streams the whole input image through the PersistentStatisticsImageFilter.
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
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.