OTB  6.7.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-2019 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 
28 #include "itkImageRegionSplitter.h"
29 #include "itkVariableSizeMatrix.h"
31 
32 namespace otb
33 {
34 
53 template<class TInputImage, class TPrecision >
55  public PersistentImageFilter<TInputImage, TInputImage>
56 {
57 public:
63 
65  itkNewMacro(Self);
66 
69 
71  typedef TInputImage ImageType;
72  typedef typename ImageType::Pointer InputImagePointer;
73  typedef typename ImageType::RegionType RegionType;
74  typedef typename ImageType::SizeType SizeType;
75  typedef typename ImageType::IndexType IndexType;
76  typedef typename ImageType::PixelType PixelType;
77  typedef typename ImageType::InternalPixelType InternalPixelType;
78 
79  typedef TPrecision PrecisionType;
81 
83  itkStaticConstMacro(ImageDimension, unsigned int, TInputImage::ImageDimension);
84 
88 
93 
101 
104  {
105  return this->GetNbRelevantPixelsOutput()->Get();
106  }
107  CountObjectType* GetNbRelevantPixelsOutput();
108  const CountObjectType* GetNbRelevantPixelsOutput() const;
110 
113  {
114  return this->GetMinOutput()->Get();
115  }
116  PixelObjectType* GetMinimumOutput();
117  const PixelObjectType* GetMinimumOutput() const;
119 
122  {
123  return this->GetMaxOutput()->Get();
124  }
125  PixelObjectType* GetMaximumOutput();
126  const PixelObjectType* GetMaximumOutput() const;
128 
132  {
133  return this->GetComponentMeanOutput()->Get();
134  }
135  RealObjectType* GetComponentMeanOutput();
136  const RealObjectType* GetComponentMeanOutput() const;
138 
142  {
143  return this->GetComponentCorrelationOutput()->Get();
144  }
145  RealObjectType* GetComponentCorrelationOutput();
146  const RealObjectType* GetComponentCorrelationOutput() const;
148 
152  {
153  return this->GetComponentCovarianceOutput()->Get();
154  }
155  RealObjectType* GetComponentCovarianceOutput();
156  const RealObjectType* GetComponentCovarianceOutput() const;
158 
161  {
162  return this->GetMeanOutput()->Get();
163  }
164  RealPixelObjectType* GetMeanOutput();
165  const RealPixelObjectType* GetMeanOutput() const;
167 
170  {
171  return this->GetSumOutput()->Get();
172  }
173  RealPixelObjectType* GetSumOutput();
174  const RealPixelObjectType* GetSumOutput() const;
176 
179  {
180  return this->GetCorrelation()->Get();
181  }
182  MatrixObjectType* GetCorrelationOutput();
183  const MatrixObjectType* GetCorrelationOutput() const;
185 
188  {
189  return this->GetCovarianceOutput()->Get();
190  }
191  MatrixObjectType* GetCovarianceOutput();
192  const MatrixObjectType* GetCovarianceOutput() const;
194 
198  DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override;
199  using Superclass::MakeOutput;
200 
201  void Reset(void) override;
202 
203  void Synthetize(void) override;
204 
205  itkSetMacro(EnableMinMax, bool);
206  itkGetMacro(EnableMinMax, bool);
207 
208  itkSetMacro(EnableFirstOrderStats, bool);
209  itkGetMacro(EnableFirstOrderStats, bool);
210 
211  itkSetMacro(EnableSecondOrderStats, bool);
212  itkGetMacro(EnableSecondOrderStats, bool);
213 
214  itkSetMacro(IgnoreInfiniteValues, bool);
215  itkGetMacro(IgnoreInfiniteValues, bool);
216 
217  itkSetMacro(IgnoreUserDefinedValue, bool);
218  itkGetMacro(IgnoreUserDefinedValue, bool);
219 
220  itkSetMacro(UserIgnoredValue, InternalPixelType);
221  itkGetMacro(UserIgnoredValue, InternalPixelType);
222 
223  itkSetMacro(UseUnbiasedEstimator, bool);
224  itkGetMacro(UseUnbiasedEstimator, bool);
225 
226 protected:
228 
230 
234  void AllocateOutputs() override;
235 
236  void GenerateOutputInformation() override;
237 
238  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
239 
241  void ThreadedGenerateData(const RegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
242 
243 private:
244  PersistentStreamingStatisticsVectorImageFilter(const Self &) = delete;
245  void operator =(const Self&) = delete;
246 
250 
251 
252  /* use an unbiased estimator to compute the covariance */
254 
255  std::vector<PixelType> m_ThreadMin;
256  std::vector<PixelType> m_ThreadMax;
259  std::vector<RealPixelType> m_ThreadFirstOrderAccumulators;
260  std::vector<MatrixType> m_ThreadSecondOrderAccumulators;
261 
262  /* Ignored values */
266  std::vector<unsigned int> m_IgnoredInfinitePixelCount;
267  std::vector<unsigned int> m_IgnoredUserPixelCount;
268 
269 }; // end of class PersistentStreamingStatisticsVectorImageFilter
270 
297  public PersistentFilterStreamingDecorator<PersistentStreamingStatisticsVectorImageFilter<TInputImage, TPrecision> >
298 {
299 public:
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  }
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 
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 
517 
518 private:
519  StreamingStatisticsVectorImageFilter(const Self &) = delete;
520  void operator =(const Self&) = delete;
521 
522 };
523 
524 } // end namespace otb
525 
526 #ifndef OTB_MANUAL_INSTANTIATION
528 #endif
529 
530 #endif
itk::Size< Monteverdi_DIMENSION > SizeType
Definition: mvdTypes.h:137
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:90
unsigned int CountType
Definition: mvdTypes.h:80
itk::SimpleDataObjectDecorator< RealPixelType > RealPixelObjectType
static const std::string Filter
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:133
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
Monteverdi_FLOATING_TYPE RealType
Definition: mvdTypes.h:84
unsigned int ThreadIdType
#define otbSetObjectMemberMacro(object, name, type)
Definition: otbMacro.h:80
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.