18 #ifndef __otbStreamingCompareImageFilter_txx
19 #define __otbStreamingCompareImageFilter_txx
24 #include "itkNumericTraits.h"
31 template<
class TInputImage>
34 m_ThreadMinRef(1), m_ThreadMaxRef(1), m_Count(1)
36 this->SetNumberOfRequiredInputs( 2 );
42 for (
int i = 1; i < 4; ++i)
49 this->GetPSNROutput()->Set(itk::NumericTraits<RealType>::max());
50 this->GetMSEOutput()->Set(itk::NumericTraits<RealType>::max());
51 this->GetMAEOutput()->Set(itk::NumericTraits<RealType>::max());
59 template<
class TInputImage>
65 this->SetNthInput(0, const_cast<TInputImage *>(image));
71 template<
class TInputImage>
77 this->SetNthInput(1, const_cast<TInputImage *>(image));
80 template<
class TInputImage>
85 if (this->GetNumberOfInputs()<1)
92 template<
class TInputImage>
97 if (this->GetNumberOfInputs()<2)
104 template<
class TInputImage>
117 return static_cast<itk::DataObject*
>(RealObjectType::New().GetPointer());
126 template<
class TInputImage>
134 template<
class TInputImage>
142 template<
class TInputImage>
150 template<
class TInputImage>
158 template<
class TInputImage>
166 template<
class TInputImage>
174 template<
class TInputImage>
179 Superclass::GenerateOutputInformation();
180 if (this->GetInput())
182 this->GetOutput()->CopyInformation(this->GetInput());
183 this->GetOutput()->SetLargestPossibleRegion(this->GetInput()->GetLargestPossibleRegion());
185 if (this->GetOutput()->GetRequestedRegion().GetNumberOfPixels() == 0)
187 this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetLargestPossibleRegion());
191 template<
class TInputImage>
203 template<
class TInputImage>
210 RealType squareOfDifferences, absoluteValueOfDifferences;
212 int numberOfThreads = this->GetNumberOfThreads();
219 squareOfDifferences = absoluteValueOfDifferences = itk::NumericTraits<RealType>::Zero;
223 minimumRef = itk::NumericTraits<PixelType>::max();
224 maximumRef = itk::NumericTraits<PixelType>::NonpositiveMin();
226 for (i = 0; i < numberOfThreads; ++i)
229 squareOfDifferences += m_SquareOfDifferences[i];
230 absoluteValueOfDifferences += m_AbsoluteValueOfDifferences[i];
232 if (m_ThreadMinRef[i] < minimumRef)
234 minimumRef = m_ThreadMinRef[i];
236 if (m_ThreadMaxRef[i] > maximumRef)
238 maximumRef = m_ThreadMaxRef[i];
243 mse = (count != 0) ? squareOfDifferences / static_cast<RealType>(count) : 0.;
245 mae = (count != 0) ? absoluteValueOfDifferences / static_cast<RealType>(count) : 0.;
248 psnr = (vcl_abs(mse)>0.0000000001 && (maximumRef-minimumRef)>0.0000000001) ? 10.*vcl_log10(((maximumRef-minimumRef)*(maximumRef-minimumRef))/mse):0.;
250 this->GetMSEOutput()->Set(mse);
251 this->GetMAEOutput()->Set(mae);
252 this->GetPSNROutput()->Set(psnr);
255 template<
class TInputImage>
260 int numberOfThreads = this->GetNumberOfThreads();
263 m_Count.SetSize(numberOfThreads);
264 m_SquareOfDifferences.SetSize(numberOfThreads);
265 m_AbsoluteValueOfDifferences.SetSize(numberOfThreads);
267 m_ThreadMinRef.SetSize(numberOfThreads);
268 m_ThreadMaxRef.SetSize(numberOfThreads);
271 m_Count.Fill(itk::NumericTraits<long>::Zero);
272 m_SquareOfDifferences.Fill(itk::NumericTraits<RealType>::Zero);
273 m_AbsoluteValueOfDifferences.Fill(itk::NumericTraits<RealType>::Zero);
274 m_ThreadMinRef.Fill(itk::NumericTraits<PixelType>::max());
275 m_ThreadMaxRef.Fill(itk::NumericTraits<PixelType>::NonpositiveMin());
278 template<
class TInputImage>
305 realValue1 =
static_cast<RealType>(value1);
308 realValue2 =
static_cast<RealType>(value2);
310 if (value1 < m_ThreadMinRef[threadId])
312 m_ThreadMinRef[threadId] = value1;
314 if (value1 > m_ThreadMaxRef[threadId])
316 m_ThreadMaxRef[threadId] = value1;
319 m_SquareOfDifferences[threadId] += ( realValue1 - realValue2 ) * ( realValue1 - realValue2 );
320 m_AbsoluteValueOfDifferences[threadId] += vcl_abs( realValue1 - realValue2 );
324 progress.CompletedPixel();
327 template <
class TImage>
332 Superclass::PrintSelf(os, indent);
334 os << indent <<
"PSNR: " << this->GetPSNR() << std::endl;
335 os << indent <<
"MSE: " << this->GetMSE() << std::endl;
336 os << indent <<
"MAE: " << this->GetMAE() << std::endl;