OTB  7.2.0
Orfeo Toolbox
otbStreamingCompareImageFilter.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 otbStreamingCompareImageFilter_h
23 #define otbStreamingCompareImageFilter_h
24 
26 #include "itkNumericTraits.h"
27 #include "itkArray.h"
28 #include "itkSimpleDataObjectDecorator.h"
30 
31 namespace otb
32 {
33 
50 template <class TInputImage>
51 class ITK_EXPORT PersistentCompareImageFilter : public PersistentImageFilter<TInputImage, TInputImage>
52 {
53 public:
57  typedef itk::SmartPointer<Self> Pointer;
58  typedef itk::SmartPointer<const Self> ConstPointer;
59 
61  itkNewMacro(Self);
62 
65 
67  typedef TInputImage ImageType;
68  typedef typename TInputImage::Pointer InputImagePointer;
69 
70  typedef typename TInputImage::RegionType RegionType;
71  typedef typename TInputImage::SizeType SizeType;
73  typedef typename TInputImage::PixelType PixelType;
74  typedef itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType;
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 
88  typedef itk::SimpleDataObjectDecorator<RealType> RealObjectType;
89  typedef itk::SimpleDataObjectDecorator<PixelType> PixelObjectType;
90 
92  const TInputImage* GetInput1();
93  const TInputImage* GetInput2();
95 
97  void SetInput1(const TInputImage* image);
98 
100  void SetInput2(const TInputImage* image);
101 
103  RealType GetPSNR() const
104  {
105  return this->GetPSNROutput()->Get();
106  }
107  RealObjectType* GetPSNROutput();
108  const RealObjectType* GetPSNROutput() const;
110 
112  RealType GetMSE() const
113  {
114  return this->GetMSEOutput()->Get();
115  }
116  RealObjectType* GetMSEOutput();
117  const RealObjectType* GetMSEOutput() const;
119 
121  RealType GetMAE() const
122  {
123  return this->GetMAEOutput()->Get();
124  }
125  RealObjectType* GetMAEOutput();
126  const RealObjectType* GetMAEOutput() const;
128 
130  RealType GetDiffCount() const
131  {
132  return this->GetDiffCountOutput()->Get();
133  }
134  RealObjectType* GetDiffCountOutput();
135  const RealObjectType* GetDiffCountOutput() const;
137 
138  itkGetMacro(PhysicalSpaceCheck, bool);
139  itkSetMacro(PhysicalSpaceCheck, bool);
140 
143  DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override;
144  using Superclass::MakeOutput;
145 
149  void AllocateOutputs() override;
150  void GenerateOutputInformation() override;
151  void Synthetize(void) override;
152  void Reset(void) override;
154 
155 protected:
158  {
159  }
160  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
161 
163  void ThreadedGenerateData(const RegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
164 
168  void VerifyInputInformation() override;
169 
170 private:
171  PersistentCompareImageFilter(const Self&) = delete;
172  void operator=(const Self&) = delete;
173 
174  itk::Array<RealType> m_SquareOfDifferences;
175  itk::Array<RealType> m_AbsoluteValueOfDifferences;
176  itk::Array<PixelType> m_ThreadMinRef;
177  itk::Array<PixelType> m_ThreadMaxRef;
178  itk::Array<long> m_Count;
179  itk::Array<long> m_DiffCount;
181 }; // end of class PersistentCompareImageFilter
182 
183 /*===========================================================================*/
184 
214 template <class TInputImage>
215 class ITK_EXPORT StreamingCompareImageFilter : public PersistentFilterStreamingDecorator<PersistentCompareImageFilter<TInputImage>>
216 {
217 public:
221  typedef itk::SmartPointer<Self> Pointer;
222  typedef itk::SmartPointer<const Self> ConstPointer;
223 
225  itkNewMacro(Self);
226 
229 
230  typedef typename Superclass::FilterType CompareFilterType;
233  typedef TInputImage InputImageType;
234 
236  typedef itk::SimpleDataObjectDecorator<RealType> RealObjectType;
237  typedef itk::SimpleDataObjectDecorator<PixelType> PixelObjectType;
238 
240  void SetInput1(InputImageType* input)
241  {
242  this->GetFilter()->SetInput1(input);
243  }
244 
246  void SetInput2(InputImageType* input)
247  {
248  this->GetFilter()->SetInput2(input);
249  }
250 
252  RealType GetPSNR() const
253  {
254  return this->GetFilter()->GetPSNROutput()->Get();
255  }
256  RealObjectType* GetPSNROutput()
257  {
258  return this->GetFilter()->GetPSNROutput();
259  }
260  const RealObjectType* GetPSNROutput() const
261  {
262  return this->GetFilter()->GetPSNROutput();
263  }
265 
267  RealType GetMSE() const
268  {
269  return this->GetMSEOutput()->Get();
270  }
271  RealObjectType* GetMSEOutput()
272  {
273  return this->GetFilter()->GetMSEOutput();
274  }
275  const RealObjectType* GetMSEOutput() const
276  {
277  return this->GetFilter()->GetMSEOutput();
278  }
280 
282  RealType GetMAE() const
283  {
284  return this->GetFilter()->GetMAEOutput()->Get();
285  }
286  RealObjectType* GetMAEOutput()
287  {
288  return this->GetFilter()->GetMAEOutput();
289  }
290  const RealObjectType* GetMAEOutput() const
291  {
292  return this->GetFilter()->GetMAEOutput();
293  }
295 
297  RealType GetDiffCount() const
298  {
299  return this->GetFilter()->GetDiffCountOutput()->Get();
300  }
301  RealObjectType* GetDiffCountOutput()
302  {
303  return this->GetFilter()->GetDiffCountOutput();
304  }
305  const RealObjectType* GetDiffCountOutput() const
306  {
307  return this->GetFilter()->GetDiffCountOutput();
308  }
310 
312  void SetPhysicalSpaceCheck(bool flag)
313  {
314  this->GetFilter()->SetPhysicalSpaceCheck(flag);
315  }
316 
319  {
320  return this->GetFilter()->GetPhysicalSpaceCheck();
321  }
322 
323 protected:
326 
329  {
330  }
331 
332 private:
333  StreamingCompareImageFilter(const Self&) = delete;
334  void operator=(const Self&) = delete;
335 };
336 
337 } // end namespace otb
338 
339 #ifndef OTB_MANUAL_INSTANTIATION
341 #endif
342 
343 #endif
itk::Size< Monteverdi_DIMENSION > SizeType
Definition: mvdTypes.h:137
itk::SimpleDataObjectDecorator< PixelType > PixelObjectType
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:133
const RealObjectType * GetMSEOutput() const
const RealObjectType * GetPSNROutput() const
itk::SmartPointer< const Self > ConstPointer
const RealObjectType * GetMAEOutput() const
PersistentImageFilter< TInputImage, TInputImage > Superclass
PersistentFilterStreamingDecorator< PersistentCompareImageFilter< TInputImage > > Superclass
itk::SimpleDataObjectDecorator< RealType > RealObjectType
itk::SimpleDataObjectDecorator< PixelType > PixelObjectType
Monteverdi_FLOATING_TYPE RealType
Definition: mvdTypes.h:84
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
itk::SmartPointer< const Self > ConstPointer
const RealObjectType * GetDiffCountOutput() const
itk::SimpleDataObjectDecorator< RealType > RealObjectType
This class streams the whole input image through the PersistentCompareImageFilter.
itk::NumericTraits< PixelType >::RealType RealType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Compute mean squared error, mean absolute error and PSNR of two imagee using the output requested reg...
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.